gpt4 book ai didi

angular - 在 karma 旁边使用 Jest 冲突类型,Angular 上的 Jasmine

转载 作者:行者123 更新时间:2023-12-04 11:54:22 24 4
gpt4 key购买 nike

背景

我正在研究一个起源于 angular.js 项目的项目。我们目前正在将所有内容迁移到 Angular。这意味着我们有 Angular.js 的遗留单元测试,最终将被删除。对于 Angular,我们已将所有测试迁移到 Jest。

问题

尝试同时拥有 Karma and Jasmine 时会出现问题如 Jest在项目中。遗留单元测试与它自己的 tsconfig 文件连接在一起,这些工作正常。两个库似乎都向全局环境添加了相同的函数,并且 Jest 测试以某种方式不断解析为 Jasmine类型。如果我删除 Karma and Jasmine从项目中所有的测试工作得很好。

问题

我怎样才能排除 jasmine's类型如 expect在不删除的情况下运行 jest 时 karma and jasmine完全来自项目?

我试过

我有一个单独的tsconfig.spec我在 jest.config.js 中引用的 Jest 测试文件文件。在这里,我尝试只添加想要的类型。我以为只会加载 node_modules/@types/<included> .但它仍然会包括 Jasmine 。

  "compilerOptions": {
"types": ["node", "jquery", "jest"],

我也尝试通过 typeRoots 包含它们,但这只会给我更多错误,例如: error TS2708: Cannot use namespace 'jest' as a value. .
{
"compilerOptions": {
"outDir": "../out-tsc/spec",
"typeRoots": [
"../node_modules/@types/jest"
...
],
"baseUrl": ".",
"paths": {
"*": ["./*"]
},
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"target": "es5",
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"allowJs": true
},
"files": ["polyfills.ts"],
"include": ["./app/**/*.spec.ts"]
}

不知何故,我似乎无法让 TypeScript 忽略 node_modules/@types/jasmine .任何帮助或指示将不胜感激。

最佳答案

您可以使用 jest-without-globals显式导入 describe、expect、it 和 test,覆盖这些符号的全局版本,否则这些符号将从 Jasmine 解析。

关于angular - 在 karma 旁边使用 Jest 冲突类型,Angular 上的 Jasmine ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58562802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com