Reactjs 如何等待子组件渲染
如何等待子组件加载,以便检查整个父组件Reactjs 如何等待子组件渲染,reactjs,unit-testing,react-testing-library,Reactjs,Unit Testing,React Testing Library,如何等待子组件加载,以便检查整个父组件 <MyComponent> <Child1 /> <Child2 /> </MyComponent> //单元测试 it('test parent component', () => { let mycomponent = render(<MyComponent />) expect(mycomponent.asFragment()).toMatchSn
<MyComponent>
<Child1 />
<Child2 />
</MyComponent>
//单元测试
it('test parent component', () => {
let mycomponent = render(<MyComponent />)
expect(mycomponent.asFragment()).toMatchSnapshot()
})
it('测试父组件',()=>{
让mycomponent=render()
expect(mycomponent.asFragment()).toMatchSnapshot()除外
})
渲染不包含子组件的渲染。儿童在5秒内加载。。有没有办法不去嘲笑孩子?我希望它们自己加载…您可以使用它来等待某个元素出现在DOM中
例如,如果其中一个子元素的某个元素带有“Some string”
文本:
it('testparent component',async()=>{
让mycomponent=render()
wait screen.findByText('Some string')
expect(mycomponent.asFragment()).toMatchSnapshot()除外
})
请注意,findBy*
查询(如waitFor
)有一个默认的1000ms超时,可以通过将选项对象中的超时值作为最后一个参数来增加