【发布时间】:2021-08-25 04:37:52
【问题描述】:
我需要为包含子 <Example/> 组件的包装组件编写测试。
在<Example/> 中进行了大量的嘲笑。我想要实现的是将模拟的 <Example/> 放入 <Parent/> 中,而不必再次进行模拟。
伪代码
test('test', () => { //there somehow need to swap component that is imported inside Parent render(<Parent/>) })
【问题讨论】:
-
显示代码。你试过什么?你得到了什么?
-
@slideshowp2 子组件有很多需要模拟的逻辑,但我不想在它自己的测试和测试父组件时重复测试它
-
不清楚。测试父组件时可以mock复杂的子组件。
标签: javascript reactjs testing jestjs react-testing-library