这是同样的问题,jest global variable example在这里得到了正确的回答,但关注的是打字稿。
console.log(__DEV__);
结果:
error TS2304: Cannot find name __DEV__.
全局变量__DEV__
在package.json中定义为:
"jest": {
"globals": {
"__DEV__": true
}
}
有人解决方案吗?
有关开玩笑的文档:https://jestjs.io/docs/en/next/configuration#globals-object
答案 0 :(得分:0)
在ts-jest中,必须用“ ts-jest”包装一些配置值:
"jest": {
"globals": {
"ts-jest": {
"__DEV__": true
}
}
}
,并可以使用以下代码访问代码:
console.log((global as any).__DEV__
在这里https://kulshekhar.github.io/ts-jest/user/config/tsConfig找到答案了