LoginSignup
6
8

More than 5 years have passed since last update.

Vue.js + Jest でnpm run unit をするとSecurityError: localStorage is not available for opaque originsが発生する

Posted at

Vue.jsのテストをやろうかと思って、とりあえず vue-cli で自動生成される HelloWorld.vue のテスト(npm run unit)を実行したら以下のエラーが発生したので、その対処法を残す。

1____w_v_t_tdd-sample__fish__と_connpass-event-search-app.png

見てみると、 SecurityError: localStorage is not available for opaque origins が発生している。

ググってみると、jest.config.jsに以下のパラメータを追加すれば良いとのこと。

jest.config.js
module.exports = {
  ...
  verbose: true,
  testURL: "http://localhost/",
}

これで再度実行する。

1____w_v_t_tdd-sample__fish_.png

めでたしめでたし👏

jest.config.jsでtestURLを設定していない場合は、 URLがabout:blankとなり、妥当なoriginでないと判断され、 SecurityError が発生した感じですね。

だとすると、必要なパラメータはtestURLだけなので、verboseはお好みで設定してください。
あと、testURLに指定する値はoriginの妥当性が判断できれば良いので、http://hogehogeとかでも大丈夫です(HelloWorld.vueで実行済み)。

以上です👍

6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8