ReferenceError:在 Jest + Typescript 中未定义描述

Pav*_*vel 5 typescript jestjs

使用 ts-jest 对 Jest 进行简单配置会在运行时产生错误“ReferenceError: describe is not defined”。这里最小的例子:https : //github.com/PFight/jest-ts-describe-not-defined-problem

我配置错了什么?

小智 8

我在节点 v10.14.1 中遇到了同样的问题。

只需将节点更新到 v10.16.2 即可修复错误。


Pav*_*vel 7

发现问题了。它是 jest.config.js 的下一行:

testEnvironment: 'node',
Run Code Online (Sandbox Code Playgroud)

刚刚删除它并修复了错误。


Gre*_*ees 5

我有同样的问题,但我需要 testEnvironment 是节点。解决方案是降级到"jest": "^24.9.0". 当 testEnvironment 设置为 node 时,最新版本似乎有问题。

更新

根据此评论https://github.com/facebook/jest/issues/9538#issuecomment-604522345,这个问题似乎已在 jest 25.2.2 中得到修复, 但我还没有对其进行测试。