Categories
JavaScript Answers

How to fix the SecurityError: localStorage is not available for opaque origins error with Jest?

Spread the love

Sometimes, we want to fix the SecurityError: localStorage is not available for opaque origins error with Jest.

In this article, we’ll look at how to fix the SecurityError: localStorage is not available for opaque origins error with Jest.

How to fix the SecurityError: localStorage is not available for opaque origins error with Jest?

To fix the SecurityError: localStorage is not available for opaque origins error with Jest, we can change our Jest config.

For instance, we add

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

to set testURL to the URL of the app being tested.

If we have multiple projects being tested, we write

module.exports = {
  verbose: true,

  projects: [{
    runner: 'jest-runner',
    testURL: "http://localhost/",

    // ...
  }]
}

to set the testURL for each project in projects to the URL of the app being tested.

Conclusion

To fix the SecurityError: localStorage is not available for opaque origins error with Jest, we can change our Jest config.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *