如何用笑话/酵素获得渲染时间?(How to get the times of render with jest/enzyme?)
喜欢这个:
const root = mount(...); expect(root.render.mock.calls.length).tobe(1);like this:
const root = mount(...); expect(root.render.mock.calls.length).tobe(1);最满意答案
另外嘲笑,由@Whj建议你可以间谍渲染。
const renderSpy = jest.spyOn(root.instance(), 'render'); root.instance().forceUpdate(); // Needed to bound spy to component's instance expect(renderSpy.mock.calls.length).toBe(1);Additionaly to mocking, suggested by @Whj you can just spyOn render.
const renderSpy = jest.spyOn(root.instance(), 'render'); root.instance().forceUpdate(); // Needed to bound spy to component's instance expect(renderSpy.mock.calls.length).toBe(1);更多推荐
发布评论