Modals cannot be tested with React's TestUtil
See original GitHub issuereact-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:
- Created 8 years ago
- Comments:29 (4 by maintainers)
Top 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 >
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 Free
Top 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
Bump. We’re currently struggling this as well. Has anyone figured out a reasonable pattern for testing with enzyme?
This blog post has some examples for testing react-modal with enzyme: http://remarkablemark.org/blog/2017/05/17/testing-react-modal/