Closed as not planned
Description
Describe the bug
Hi, thanks for taking a look at this!
I'm fairly new to react-native, but have a lot of experience with web testing-library variants and ran across some unexpected (to me) behavior. Query methods find nodes in non-visible modals.
I think this is what this user was getting at #508
Steps to Reproduce
Here's a simple example test I set up to test this out
// App.js
import React from "react";
import { Modal, Text, View } from "react-native";
const App = () => {
return (
<View>
<Modal visible={false}>
<View>
<Text>Exciting content</Text>
</View>
</Modal>
</View>
);
};
export default App;
// App.test.js
import React from "react";
import { render, fireEvent } from "@testing-library/react-native";
import App from "./App";
it("shows the modal on button click", () => {
const { queryByText } = render(<App />);
expect(queryByText("Exciting content")).toBeNull(); // fails
});
Expected behavior
I'd expect this test to pass, since there's no modal content visible to the user while the modal is not visible.
If this is expected behavior, is there a recommended way to test appearance/disappearance modals?
Versions
@testing-library/[email protected]
Metadata
Metadata
Assignees
Labels
No labels