使用酶在测试中获取功能子组件的道具

问题描述 投票:1回答:1

是否有办法通过show获取Child组件的Enzyme props

const [show] = useState(true)
<Parent>
  <Child show={show} />
</Parent>

ParentChild都是功能组件

reactjs unit-testing jestjs enzyme
1个回答
0
投票

可能可以使用diveprops

假设您在App组件中包含这些组件。

// We create a shallow render of the component 
// that holds `const [show] = useState(true)` and renders `<Parent> ... </Parent>`
const wrapper = shallow(<App />);

expect(
  wrapper
    .find(Parent)
    .dive()
    .find(Child)
    .dive()
    .props().show
).to.equal(true);

© www.soinside.com 2019 - 2024. All rights reserved.