【发布时间】:2018-10-08 16:17:45
【问题描述】:
我正在测试的 React 组件中有以下功能。
renderLoginLink(caption) {
return (
<a href="#" id="lnkAuthenticateWithGoogle" onClick={() => this.props.actions.authenticateWithGoogle()}>
{caption}
</a>
);
}
当我运行 jest --coverage 时,该功能被标记。我已经为通过的函数编写了以下测试。
describe('Login', () => {
it('calls renderLoginLink()', () => {
const actions = {
authenticateWithGoogle: jest.fn()
}
const expectedNode = <a href="#" id="lnkAuthenticateWithGoogle" onClick={() => actions}>testCaption</a>
let node = document.createElement('div');
let instance = ReactDOM.render(<Login {...initialState} />, node);
expect(JSON.stringify(instance.renderLoginLink("testCaption"))).toEqual(JSON.stringify(expectedNode));
});
});
我不确定我遗漏了什么,或者我可以编写什么其他测试来满足开玩笑的覆盖率。
【问题讨论】:
-
运行
jest --clearCache是否先修复它?