angular - Jest Angular 测试给出业力错误`发生未处理的异常:找不到模块'业力'`
问题描述
我正在尝试在 Angular 中使用玩笑测试。我已经完成了这里描述的所有配置在此处 输入链接描述
这是我的 package.json
{
"name": "jest-test",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "jest",
"test:watch": "jest --watch",
"test:ci": "jest -ci --runInBand",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~10.2.0",
"@angular/common": "~10.2.0",
"@angular/compiler": "~10.2.0",
"@angular/core": "~10.2.0",
"@angular/forms": "~10.2.0",
"@angular/platform-browser": "~10.2.0",
"@angular/platform-browser-dynamic": "~10.2.0",
"@angular/router": "~10.2.0",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1002.0",
"@angular/cli": "~10.2.0",
"@angular/compiler-cli": "~10.2.0",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jest": "^26.6.3",
"jest-preset-angular": "^8.3.2",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
},
"jest": {
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
"transform": {
"^.+\\.(ts|html)$": "ts-jest",
"^.+\\.js$": "babel-jest"
}
}
}
这是 tsconfig.spec.ts
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"node",
"jest",
"jsdom"
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
我还添加了 setupjest.ts。我只有 import 'jest-preset-angular';
现在,当我运行 ng test 时,它给出了 karma not found 错误。
解决方案
我建议您使用 briebug jest 原理图将 jest 添加到您的项目(https://www.npmjs.com/package/@briebug/jest-schematic),因为它是维护的,而不是使用 2 年前的博客文章。
推荐阅读
- javascript - jsPDF——字体这么大,每个字母占 3 页?
- firebase - Flutter,当我从 firebase 消息发送通知时,我收到此错误并且我的应用程序冻结
- python - 如何用 scipy 计算单边公差区间
- linker - 在 gnu 链接描述文件中使用 ALIGN 命令
- python-3.x - 在输入文本中查找所有网站地址(Python)
- java - 当我没有中间证书时,如何使用 Bouncy Castle 获取根 CA 和最终实体之间的证书路径?
- flutter - 容器小部件中的应用溢出
- javascript - Firebase:在前端将对象数组转换为真正的数组 - 奇怪的行为
- javascript - Emscripten 中的“Module”变量机制,同时将 Pthread 编译为 worker
- c# - NET Core 3.1:在插入和更新时更新实体的字段