Non-visible modal content shows up in queries
See original GitHub issueDescribe 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 https://github.com/callstack/react-native-testing-library/issues/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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:19 (5 by maintainers)
Top Results From Across the Web
Modal Dialog is Loaded But Invisible - Stack Overflow
When I use the button's trigger with data-toggle and data-target, the modal is showing up visible. This is what I have tried to...
Read more >Modal - Bootstrap
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Read more >Considerations for Styling a Modal | CSS-Tricks
A small box that pops up to tell you something important. ... the default .modal class be hidden by default, likely with display:...
Read more >How to pass data into a bootstrap modal? - GeeksforGeeks
A modal is a popup or dialog box that requires some action to be ... from the HTML document which gets displayed when...
Read more >Modal not populating with PHP data. - Material Design for ...
Hi Rafal, I tried to replace all the css and js link with your but the model appears without the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just opened a PR on react-native repository to update the mock so the Modal doesn’t render its children when the visible prop is false. It should fix your issue 😃
The other option is to send a PR to React Native adding accessibility props for Modal.