question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-visible modal content shows up in queries

See original GitHub issue

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 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

@testing-library/react-native@7.1.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
AntoineDoubovetzkycommented, Oct 7, 2021

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 😃

3reactions
satya164commented, Apr 13, 2021

For the modal from react-native, there is no accessibility prop according to the props given in the doc. Its prop visible sounds like the only option unfortunately.

The other option is to send a PR to React Native adding accessibility props for Modal.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found