Skip to content

Instantly share code, notes, and snippets.

@MrRhodes
Created August 2, 2017 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrRhodes/8b026cdc92841d643debba1b89050d3f to your computer and use it in GitHub Desktop.
Save MrRhodes/8b026cdc92841d643debba1b89050d3f to your computer and use it in GitHub Desktop.
Should not find conditionally rendered child?
import React from 'react';
import { shallow } from 'enzyme';
class ConditionalParent extends React.Component {
render() {
return !!this.props.visible && (<div>{this.props.children}</div>);
}
}
class Child extends React.Component {
render() {
return <div>Hello</div>;
}
}
it('should have no child.', () => {
const wrapper = shallow(
<div>
<ConditionalParent>
<Child />
</ConditionalParent>
</div>
);
expect(wrapper.find(Child).length).toBe(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment