npmnode.js95% confidence\u2191 175

Jest SecurityError: localStorage is not available for opaque origins

Full error message
When I want to run my project with the command npm run test, I get the error below. What is causing this?

FAIL
● Test suite failed to run

SecurityError: localStorage is not available for opaque origins at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
      at Array.forEach (<anonymous>)

In case, if you are accessing your application with a http://localhost prefix, you need to update your jest configuration (in your jest.config.js) as, "jest": { "verbose": true, "testURL": "http://localhost/" } In case you do not already have any jest configuration, just include the configuration in your package.json. For example: { "name": "...", "description": "...", ... "jest": { "verbose": true, "testURL": "http://localhost/" } } or in jest.config.js : module.exports = { verbose: true, testURL: "http://localhost/", ... } or if you have projects configured: module.exports = { verbose: true, projects: [{ runner: 'jest-runner', testURL: "http://localhost/", // ... }] } for configuration in package.json, testURL is removed in jest v28. Now you should use testEnvironmentOptions to pass url option like that: "jest": { "verbose": true, "testEnvironmentOptions": { "url": "http://localhost/" } }

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/1f202d9395aa7a942bf6821d835e386f2c590b34698e0f7fdda05c357a3c0d7f
hash \u00b7 1f202d9395aa7a942bf6821d835e386f2c590b34698e0f7fdda05c357a3c0d7f
Jest SecurityError: localStorage is not available for opaque… — DepScope fix | DepScope