Jest SecurityError: localStorage is not available for opaque origins

前端 未结 12 513
礼貌的吻别
礼貌的吻别 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:49

    I just had this cropping up in a large monorepo (in unit tests, that otherwise wouldn't have required jsdom). Explicitly setting the following in our jest.config.js (or the package.json equivalent) also alleviated that issue:

    module.exports = {
      testEnvironment: 'node'
    }
    

    Update: As Nicolas mentioned below (thanks!), you can also add the following flags if you're not using any config files:

    jest --testEnvironment node    
    # or 
    jest --env=node
    

提交回复
热议问题