Jest SecurityError: localStorage is not available for opaque origins

前端 未结 12 537
礼貌的吻别
礼貌的吻别 2021-01-30 19:24

When I want to run my project with the command npm run test, I get the error below. What is causing this?

FAIL
● Test suite failed to run

SecurityE         


        
12条回答
  •  逝去的感伤
    2021-01-30 19:33

    In case, if you are accessing your application with a http://localhost prefix, you need to update your jest configuration (in your jest.config.js) as,

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

    In case you do not already have any jest configuration, just include the configuration in your package.json. For example:

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

    or in jest.config.js :

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

    or if you have projects configured:

    module.exports = {
      verbose: true,
    
      projects: [{
        runner: 'jest-runner',
        testURL: "http://localhost/",
    
        // ...
      }]
    }
    

提交回复
热议问题