NodeJS 正在将Jest升级到v29 -找不到错误测试环境jest-environment-jsdom

k5hmc34c  于 2023-01-04  发布在  Node.js
关注(0)|答案(2)|浏览(533)

有人成功升级到最新的Jest版本29吗?
我收到一个错误:

Error: Test environment jest-environment-jsdom cannot be found. Make sure the testEnvironment configuration option points to an existing node module.
kfgdxczn

kfgdxczn1#

Jest团队在版本28.0.1中添加了更多descriptive error message

Error: ...
As of Jest 28 "jsdom" is no longer shipped by default, make sure to install it separately.

安装jsdom程序包可解决此问题:

# npm
npm install -D jest-environment-jsdom
# yarn
yarn add -D jest-environment-jsdom
xwmevbvl

xwmevbvl2#

Jest 27将附带一个新的测试运行器“jest-circus”和默认的Node.js环境Documentation
只需从您jest配置中删除以下行:

{
      "jest": {
        "testEnvironment": "jsdom",
      }
    }

默认情况下现在应该是:

{
  "jest": {
    "testEnvironment": "node",
  }
}

相关问题