【发布时间】:2020-07-24 17:21:06
【问题描述】:
使用 jest 和 react 测试库。
这似乎很重要,但我很想念它。你如何模拟一个子组件,但测试父组件是否使用正确的道具调用它?在这种情况下,我想测试 parent.js 并模拟出子组件。
父.js
import Child from './child'
const Parent = (props) => {
const {firstname} = props;
<Child name={firstname} />
}
test.js
import Parent from '../parent'
jest.mock('./child');
it('should render properly'), () => {
render(<Parent firstname='bob'/>);
expect('child').toBeCalledWith({ name: 'bob' });
}
【问题讨论】:
标签: reactjs jestjs mocking react-testing-library