-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
react-testing-library
version: 6.1.2react
version: 16.8.6node
version: 11.13.0yarn
version: 1.15.2
Relevant code or config:
class Hider extends React.Component {
state = {
visible: true
};
render() {
return (
<div>
<span>{this.props.text || "hi"}</span>
<button onClick={() => this.setState({ visible: false })}>hide</button>
<div>{this.props.children}</div>
</div>
);
}
}
class App extends React.Component {
render() {
return (
<div>
<Hider>
<span>hello world</span>
</Hider>
</div>
);
}
}
it("should not work properly", async () => {
const wrapper = render(<App visible={false} />);
fireEvent.click(wrapper.getByText("hide"));
await wait(() => {
expect(wrapper.queryByText("hide")).not.toBeInTheDocument();
});
});
What you did:
I was writing to test a modal component that hides children by returning null.
What happened:
Querying the container for the text of the button results in returning the button, even though that button isn't present in the DOM.
The error message is {"location": null} contains: <button />
A snapshot of that error:
Reproduction:
I created a reproduction of the issue here: https://github.com/bolivier/react-testing-library-reproduction
Problem description:
Event though the components are not present, they are found and the tests fail
Suggested solution:
I'm unsure of a solution. I did notice that everything behaves as expected if there's no component nesting. So if the App
component handles the visibility, then the tests will pass.
Metadata
Metadata
Assignees
Labels
No labels