【发布时间】:2020-08-26 03:49:49
【问题描述】:
【问题讨论】:
【问题讨论】:
首先,尝试在您的package.json 中全局安装相同版本的 Jest。使用此命令 -
npm i -g jest@xx.yy.zz
将 xx.yy.zz 替换为package.json 中提到的版本。然后运行这个命令来测试单个文件。
jest -f "shared.service.spec.ts"
应该适用于单个文件,但如果您想在一个目录或文件夹中运行所有测试,请使用此命令 -
jest --testPathPattern=src/app/shared/components
或
只需从当前 Angular 项目的 node_modules 运行它。从 Angular 根文件夹运行这些命令。
./node_modules/jest/bin/jest.js -f shared.service.spec.ts
./node_modules/jest/bin/jest.js --testPathPattern=src/app/shared/components
【讨论】:
解决方法是使用
ng test -f <ComponentName>
其中<ComponentName> 是组件的实际名称,不是它的路径,也不是规范文件的名称,例如:
ng test -f HomeComponent
有关 angular github repo here 的更多信息。它解释了在 Angular 中使用 Jest 添加了一个自定义构建器,这就是不支持 --include 的原因。
【讨论】: