Jest: SecurityError: localStorage is not available for opaque origins

Created on 27 Jul 2018  路  9Comments  路  Source: facebook/jest

馃悰 Bug Report

Hi guys!
I've made setup without create-react-app and when I try to run tests I got error:
image

Test is very simple :
it('first test', () => {
expect(123).toBe(123)
})

Expected behavior

I'd like to be able to pass my tests

Most helpful comment

related to jsdom/jsdom#2304

You can set the testURL of the jest configuration like this:

  "jest": {
    "verbose": true,
    "testURL": "http://localhost/"
  }

All 9 comments

I see this also

related to jsdom/jsdom#2304

You can set the testURL of the jest configuration like this:

  "jest": {
    "verbose": true,
    "testURL": "http://localhost/"
  }

Ok. The fix is to set testURL: "http://localhost/" in jest config.
But I have another problem. All running process is very slow, It last about 5-7 sec even if I run my tests with --watch.
Anyone knows how to increase performance?
Fast fix: I changed my Jest version from "23.4.1" to "22.4.1"

For anyone just starting to use Jest and running into this error, this is how you define a Jest configuration: https://jestjs.io/docs/en/configuration.html

Update: setting testURL works. I had a different problem, with my babelrc.

When I set testURL, I get a new error at all instances of import Enzyme

SyntaxError: Unexpected token import

Not sure if this is related to react-sass-starterkit test setup or not, since this is my first time trying to do react testing with jest...

If you are using jsdom, make sure you include url

const dom = new JSDOM(``, {
url: "https://example.org/",
});

If use vue-cli, only necesary agregate to MyProjectVueCli/test/unit/jest.config.js

 .. 
 ..
  collectCoverageFrom: [
   ..
    '!**/node_modules/**'
  ],
  **testURL:"http://localhost:8080"**
}

related to jsdom/jsdom#2304

You can set the testURL of the jest configuration like this:

  "jest": {
    "verbose": true,
    "testURL": "http://localhost/"
  }

Ya it solve my issue

Was this page helpful?
0 / 5 - 0 ratings