Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
Created February 15, 2018 06:19
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 AndrewRayCode/793700c88b10dc5032346f5965c6ede0 to your computer and use it in GitHub Desktop.
Save AndrewRayCode/793700c88b10dc5032346f5965c6ede0 to your computer and use it in GitHub Desktop.
// generic ui component
class Panel {
render() {
return <div>
<b>{this.props.title}</b>
<p>{this.props.body}</p>
</div>;
}
}
// Component I want to test...
class ComponentToTest {
get title() {
return <div>
title text
</div>;
}
get body() {
return <div>
body text
</div>;
}
render() {
return <div>
<Panel title={this.title} body={this.body} />
</div>;
}
}
it('does a thing', () => {
const wrapper = shallow(<ComponentToTest />);
/*
here, since wrapper shallow doesn't render <Panel />, it won't put the title
and body on the page. Is there a way to test this WITHOUT manually testing the
body/title methods by hand (I still want to render the whole component) and WITHOUT
manually finding the panel element and calling its render method or specific methods
on it?
Changing the API of panel is an option
*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment