angular - 在 Angular 中测试 utils 文件。最佳实践是什么?

标签 angular testing karma-jasmine

在 Angular 中,我想分享一些在我的测试中使用的实用工具。

这样做的最佳实践/标准是什么?

即要测试组件/服务/无论您创建一个具有相同名称和扩展名 .spec.ts 的文件,并将其放在同一文件夹中。对于测试实用程序,最好的放置和命名是什么?也以 .spec.ts 结尾?

最佳答案

使用文件扩展名 .spec.ts 以便 Karma 可以识别包含测试的文件。这是您在 test.ts 文件中指定的内容。

const context = require.context('./', true, /\.spec\.ts$/);

我会将测试实用程序类放在 .ts 文件中的 src/app/shared/testing 文件夹中。为了提高测试的可靠性(并提高整体代码覆盖率统计数据),您还应该为每个测试实用程序类提供相应的 .spec.ts 文件。

关于angular - 在 Angular 中测试 utils 文件。最佳实践是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58852483/

相关文章:

Angular:同时使用 ViewChild 和输入、副作用还是最佳实践?

java - Jersey 容器监听器中事件的集成测试

testing - 无法使用 Angular-cli 运行 Karma

angular - 让 Karma 1.1.0 和 Angular 2 测试工作的问题

testing - 无法在 Angular 2.0.0 测试中加载 .html

angular - oidc-client 与 IdentityServer3 - Angular2 SPA,如何刷新数据访问 token

Angular AOT 编译器 - TypeError : this. compiler.analyzeModulesAsync 不是函数

php - 运行 behat 时出错

testing - 您如何记录您的网络浏览器要求?

angularjs - 测试 Angular 应用程序时遇到问题/错误 : 'DEPRECATION: describe with no children (describe() or it())