How to use Popper.js in Jest / JSDOM?
See original GitHub issueCodePen demo
https://codepen.io/pen?template=wGqJEz
Steps to reproduce the problem
- Run UI tests with jsdom
- Get exception
TypeError: document.createRange is not a function
What is the expected behavior?
Not to get an exception
What went wrong?
Obviously this is not popper’s fault, but maybe it can be fixed here.
Any other comments?
Thanks for the awesome library, I hope this doesn’t come across as disrespectful. The jsdom issue gives the feeling that this won’t implemented anytime soon. I would like to know more about why createRange
is used and can we replace it with something else or fall back to another solution if the browser doesn’t support it.
Browsers newer than IE8 already support this so I can’t find another use case other than testing with jsdom
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:20
- Comments:42 (14 by maintainers)
Top Results From Across the Web
How to use Popper.js in Jest / JSDOM? · Issue #478 - GitHub
Yes as I said, Popper.js is probably never going to work in JSDOM, it relies on real browser DOM APIs to work.
Read more >Loading popper.js in Jest
First we followed the instruction on popper.js on How to use Popper.js in Jest, which provides two ways of mock the library.
Read more >How to use Reakit popover in jest / jsdom? · Reakit
I'm wondering, how I could mock popper.js, when it's not a direct dependency for me. I'm using Reakit Popover in one of my...
Read more >popperjs-final - npm
Start using popperjs-final in your project by running `npm i popperjs-final`. There are no other projects in the npm registry using ...
Read more >document.createRange is not a function` error while testing ...
2 Answers 2 · This is a good thing to mention, however using Enzyme instead of React-Testing-Library, I did not have to mock...
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 was having the same issue with enzyme
mount()
and mocking did not work. However, adding this to my setupTests.js file made everything work.Just to close the loop on this…
I also discovered that following works and may be more desirable for some folks.
Create a folder/file called
__mocks__/popper.js.js
adjacent to yournode_modules
directory containing the following code. Jest will pick it up automatically.