关键是使用笑话
spyOn方法。应该是这样的:
const spy = jest.spyOn(Component.prototype, 'methodName');const wrapper = mount(<Component {...props} />);wrapper.instance().methodName();expect(spy).toHaveBeenCalled();如此处所示:测试功能是否被称为反应和酶
请注意 ,最好的做法是在每次测试运行后清除监视功能
let spyafterEach(() => { spy.mockClear()})https://facebook.github.io/jest/docs/en/jest-
object.html#jestclearallmocks



