If returning an empty string/null inside a react component and trying to call the type() function on that node will result in the following error: Cannot read property 'type' of null. This can be reproduced when trying to the use the shallow rendering filterWhere() API method.
Please see the below code snippet:
const MyComp = ({foo}) => {
return (
<div>
<MyOtherComp />
{foo !== 0 && (
<MyAnotherComp />
)}
</div>
);
});
it('should rock the world', () => {
const wrapper = shallow(<MyComp foo={0});
const result = wrapper.findWhere(n => (
n.type() === MyAnotherComp
);
expect('nothing because "Cannot read property \'type\' of null" will occur');
});
In my test I want to check if the value of a specific prop is for e.g. {bar} then component should not be rendered.
Are there any workarounds for this issue ?
Thanks !
If returning an empty string/null inside a react component and trying to call the type() function on that node will result in the following error: Cannot read property 'type' of null. This can be reproduced when trying to the use the shallow rendering filterWhere() API method.
Please see the below code snippet:
In my test I want to check if the value of a specific prop is for e.g. {bar} then component should not be rendered.
Are there any workarounds for this issue ?
Thanks !