我有一个组件在某些条件下在渲染中返回 null:
render() {
  if (this.props.isHidden) {
      return null;
  }
  return <div>test</div>;
}
当 isHidden 为真时,我想检查组件是否为空,并使用 jest 和酶:
describe('myComp', () => {
    it('should not render if isHidden is true', () => {
        const comp = shallow(<myComp isHidden={true} />);
        expect(comp.children().length).toBe(0);
    });
});
这有效,但有没有更惯用的方式来编写这个测试?测试呈现为 null 的组件是很常见的场景。