Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest tests fail - SecurityError: localStorage is not available for opaque origins #1424

Open
bigtunacan opened this issue Jul 28, 2018 · 3 comments · May be fixed by #1479
Open

Jest tests fail - SecurityError: localStorage is not available for opaque origins #1424

bigtunacan opened this issue Jul 28, 2018 · 3 comments · May be fixed by #1479

Comments

@bigtunacan
Copy link

To reproduce just generate a new project using vue init webpack my-project and choose Jest as the test suite. Then run npm run unit and it will fail with error

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 ()

This appears related to this issue with jsdom jsdom/jsdom#2304

For now there is a workaround by locking jsdom to version 11.11.0

@shayneo
Copy link

shayneo commented Aug 3, 2018

Same issue here, was able to resolve by adding
testEnvironment: 'node' to jest.config.js

@scriada
Copy link

scriada commented Aug 12, 2018

Based on the link in @bigtunacan 's original comment I was able to resolve this by adding:

testURL: 'http://localhost'

to the jest.conf.js file.

I also noticed that this filename doesn't match the default jest config filename (should be test.config.js) so jest won't pick it up without an explicit --config argument.

@sylhare sylhare mentioned this issue Nov 27, 2018
@agirorn
Copy link

agirorn commented Feb 8, 2019

When I added testEnvironment: 'node' as @shayneo suggested to a new project. I got the tests running but the following error.

> vue-webpack@1.0.0 test /home/agirorn/code-play/vue-webpack                                                                                                                                                                                  
> npm run unit && npm run e2e                                                                                                                                                                                                                 
                                                                                                                                                                                         
> vue-webpack@1.0.0 unit /home/agirorn/code-play/vue-webpack                                                                                                                                                                                  
> jest --config test/unit/jest.conf.js --coverage                                                                                                                                                                                             
                                                                                                                                                                                                                                              
● Deprecation Warning:                                                                                                                                                                                                                        

  Option "mapCoverage" has been removed, as it's no longer necessary.                                                                                                                                                                         

  Please update your configuration.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

 FAIL  test/unit/specs/HelloWorld.spec.js
  HelloWorld.vue
    ✕ should render correct contents (14ms)

  ● HelloWorld.vue › should render correct contents

    TypeError: Cannot read property 'querySelector' of undefined

       6 |     const Constructor = Vue.extend(HelloWorld);
       7 |     const vm = new Constructor().$mount();
    >  8 |     expect(vm.$el.querySelector('.hello h1').textContent)
       9 |       .toEqual('Welcome to Your Vue.js App');
      10 |   });
      11 | });

      at Object.querySelector (test/unit/specs/HelloWorld.spec.js:8:19)

But when I add the testURL: 'http://localhost' as @scriada suggest everything runs fine.

@agirorn agirorn linked a pull request Feb 8, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants