5

I got an error SecurityError: localStorage is not available for opaque origin. I tried all advises about this problem:

  • set testURL: "http://localhost/",
  • set testEnvironmentOptions: { url: 'https://localhost/' }.

All this in jest.config.js but it doesn't work for me. My jest.config.js file:

  modulePaths: ["<rootDir>/src"],
  moduleNameMapper: {
    "\\.(css|less|sass|scss)$": "identity-obj-proxy",
  },
  moduleDirectories: [
    "node_modules",
  ],
  setupFilesAfterEnv: ["mock-local-storage"],
  testEnvironment: "jsdom",
  verbose: true,
  testURL: "http://localhost/",
};```

Help me please
  • this looks related: https://stackoverflow.com/questions/51554366/jest-securityerror-localstorage-is-not-available-for-opaque-origins – Ben Clayton May 26 '22 at 13:28

1 Answers1

8

These linked answers didn't work for me. This is the only thing that did: https://jestjs.io/docs/upgrading-to-jest28#jsdom

npm i --save-dev jest-environment-jsdom

Curious how the error message lines up (it doesn't), but the new required dependency is definitely the issue on my end.

Bryan Latten
  • 332
  • 3
  • 10