react-modal: setAppElement throws error in tests
Summary:
When running in test, the lib/helpers/ariaAppHider.js:24 throws:
Error: react-modal: No elements were found for selector #app.
Expected behavior:
Should not throw errors in test.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 27
- Comments: 20
Commits related to this issue
- Workaround react modal issues to get test passing See https://github.com/reactjs/react-modal/issues/632 — committed to iancanderson/hurdle by iancanderson 2 years ago
- Set up CI (#111) * Set up CI This adds a CI workflow that: - Builds and tests the project on 3 versions of node - If branch is `main` (and build & test succeeds), deploys to production by pushin... — committed to octokatherine/word-master by iancanderson 2 years ago
- Refactor nombre de modal y ajuste para los test src:https://github.com/reactjs/react-modal/issues/632#issuecomment-378755186 — committed to sofiagaona/harry-app by sofiagaona 2 years ago
In order to fix this issue, I did the following in all my components that use react-modal:
Guys, you can just simply set a mock function for this and get out of this. taddaaaa Just write it before your describe and here you go…
Happy coding!!
I too am having the same issue, #668 didn’t fix this for me.
Great. That’s one way.
Another way would be to move the
setAppElement()to a file that doesn’t go into the tests.In case your tests really need to set the element, here is an example (but this will depend on the test environment):
was able to work around the error by setting
appElementdirectly on the modal.I got similar error . i am using
jestso i decided to follow below solutionSolution: setup global mock for React Modal and override setAppElement method
Will this problem ever be fully addressed?
I just ended up dropping this on the modal:
I got rid of the error in a dumb way.
I had the same issue,
Work around of it like this
With same principal. Thanks…