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.

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:

  1. Install latest Jest
  2. Make a clean yarn/npm install
  3. Setup a basic test case
  4. 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:closed
  • Created 5 years ago
  • Reactions:165
  • Comments:22

github_iconTop GitHub Comments

263reactions
csvancommented, Jul 27, 2018

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?

201reactions
wahengchangcommented, Jul 27, 2018

Add testEnvironment env config for non-browser enviroment

  "jest": {
    "testEnvironment": "node"
  },
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

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