2017-11-13 5 views
1

I持って、一定の条件の下で、レンダリングにnullを返しコンポーネント:冗談酵素レンダリングでnullを返しコンポーネントを反応させるのテスト方法

render() { 
    if (this.props.isHidden) { 
     return null; 
    } 

    return <div>test</div>; 
} 

isHiddenは冗談で真であるとき、私は、コンポーネントがnullであるかどうかを確認したいです酵素:

describe('myComp',() => { 
    it('should not render if isHidden is true',() => { 
     const comp = shallow(<myComp isHidden={true} />); 
     expect(comp.children().length).toBe(0); 
    }); 
}); 

これは機能しますが、この試験を書くのにもっと慣用的な方法がありますか? nullとしてレンダリングするコンポーネントのテストは、非常に一般的なシナリオです。

答えて

2
expect(comp.type()).toEqual(null) 

これだけです!

または:expect(comp.get(0)).toBeFalsy()

関連する問題