我有一个 React 组件,它返回它的 children
如果 prop isTrue
由 React 渲染是真的。如果它的 Prop isTrue
为 false-y,则组件返回 null
, React 不渲染任何东西。
我需要将它作为一个组件进行测试,安装它,传递 Prop ,并测试它的 child 是否在 Prop isTrue
时被渲染。是真的,或者我们得到null
如果 isTrue
是假的。
这是我的组件:
const RenderIf = ({ isTrue, children }) => {
if (isTrue) {
return children;
}
return null;
}
export default RenderIf
最佳答案
expect(container).toBeEmptyDOMElement()
关于javascript - 如何使用 React 测试库测试 React 组件是否返回 null 或其子级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62919547/