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.

Modals cannot be tested with React's TestUtil

See original GitHub issue

react-modal is acting outside of the purview of any of React’s test utilities.

renderedModal.getDomNode()
// => <noscript data-reactid=".0"></noscript>

React.scryRenderedDOMComponentsWithClass(renderedModal, "my-modal-class");
// => []

I see there are some work arounds that were developed circa React 0.12 but I can’t figure out why that is necessary. If I was guessing I would say that this has to do with how you mount to the DOM to properly apply the overlay. If this is true, maybe a small wrapper around those helpers as a part of the release would be a helpful thing for us app devs who want to write lots of tests 😃

https://github.com/rackt/react-modal/blob/master/specs/helper.js

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:29 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
oliversongcommented, Mar 3, 2017

Bump. We’re currently struggling this as well. Has anyone figured out a reasonable pattern for testing with enzyme?

2reactions
dy-dxcommented, May 31, 2017

This blog post has some examples for testing react-modal with enzyme: http://remarkablemark.org/blog/2017/05/17/testing-react-modal/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing a React Modal component - Stack Overflow
Due to the modal not being rendered the traditional React way, React cannot see the modal in order to use TestUtils on.
Read more >
Modals cannot be tested with React's TestUtil - - Bountysource
react -modal is acting outside of the purview of any of React's test utilities. renderedModal.getDomNode() // => <noscript data-reactid=".0"></noscript> ...
Read more >
[Solved]-Testing a React Modal component-Reactjs
Due to the modal not being rendered the traditional React way, React cannot see the modal in order to use TestUtils on. An...
Read more >
Build and Test Modal using React features and DOM events ...
In this issue, we are going to build a Modal (or Dialog) component to get familiar with testing components that rely on Portals,...
Read more >
Straightforward React UI Testing - Toptal
React natively includes models, functions, and components, all of which—by a sideways ... Testing is further supported by some fantastic React TestUtils ....
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