[英]How to get the times of render with jest/enzyme?
像這樣:
const root = mount(...);
expect(root.render.mock.calls.length).tobe(1);
@Whj建議,除了模擬之外,您還可以spyOn渲染。
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);
使用模擬功能。
root.instance().render = jest.fn(root.instance().render); // Mock Implementations
expect(root.instance().render.mock.calls.length).tobe(1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.