Iam having trouble figuring out why my test won't work. Lets say I have a component like this:
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = { flag: true };
}
render() {
return (
<div>
{
this.state.flag && (
<div>Hello there!</div>
)
}
</div>
)
}
}
Here is my test file:
it ('shows Hello There when the flag is set to true', () => {
const component = shallow(<MyComponent />);
component.setState({ flag: true });
expect(
component.containsMatchingElement(<div>Hello There</div>)
).toBe(true)
});
When I run this, it says that it is expecting true, but getting false. Am I doing something wrong?
Thanks!
Aucun commentaire:
Enregistrer un commentaire