JSDom 11.12 causes SecurityError: localStorage is not available for opaque origins
See original GitHub issue🐛 Bug Report
A clear and concise description of what the bug is.
Jsdom just recently upgraded to version 11.12, which includes support for window.localStorage
and other features. See https://github.com/jsdom/jsdom/blob/master/Changelog.md.
A fresh yarn install deduces that Jest uses this latest version, but this causes all existing Jest test cases to fail with:
SecurityError: localStorage is not available for opaque origins
To Reproduce
Steps to reproduce the behavior:
- Install latest Jest
- Make a clean yarn/npm install
- Setup a basic test case
- Run it
Expected behavior
Test case should pass.
Run npx envinfo --preset jest
Paste the results here:
System:
OS: Linux 4.15
CPU: x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Binaries:
Node: 10.7.0
Yarn: 1.7.0
npm: 6.1.0
npmPackages:
jest:
wanted: ~23.4.0
installed: 23.4.1
Issue Analytics
- State:
- Created 5 years ago
- Reactions:165
- Comments:22
Top Results From Across the Web
jest : SecurityError: localStorage is not available for opaque ...
The fix is to set a URL for your jsdom, which might need to be done through your testing environment configuration. The default...
Read more >Jest SecurityError: localStorage is not available for opaque ...
When I want to run my project with the command npm run test , I get the error below. What is causing this?...
Read more >Jest SecurityError localStorage is not available for opaque ...
I want to run my project with the command npm run test, I get the error below. What is causing ... /Window.js:257:15) at...
Read more >JSDom 11.12 causes SecurityError: localStorage is not available ...
JSDom 11.12 causes SecurityError: localStorage is not available for opaque origins.
Read more >How to use the jsdom.VirtualConsole function in jsdom
To help you get started, we've selected a few jsdom. ... { // JSDom 11.12 causes SecurityError: localStorage is not available for opaque...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
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
Update: as noted in the linked issue, adding the following to the Jest config solves the issue:
testURL: 'http://localhost'
Perhaps the default for this config option needs to be changed?
Add
testEnvironment
env config for non-browser enviroment