【发布时间】:2019-01-16 06:53:39
【问题描述】:
我有一个函数式组件,我想用模拟函数对其进行测试 (简化演示)
const remove = () => {
... do something
}
const removeButton = (props) => (
<Button onClick={() => remove()}>
Remove
</Button>
);
我试过这个测试用例
it('test remove button', () => {
const test = shallow(<removeButton/>)
const mockFunction = jest.fn()
test.instance().remove = mockFunction
test.find('Button').simulate('click')
expect(mockFunction).toHaveBeenCalled()
})
.instance().remove 无法模拟该函数,因为它超出了范围。 我将如何模拟函数 remove ?
【问题讨论】:
标签: reactjs mocking jestjs enzyme