关键是使用笑话
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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)