javascript - 我们应该在单元测试时使用 Angular TestBed 吗?

标签 javascript angular typescript jasmine karma-runner

<分区>

我们应该在单元测试时使用 Angular TestBed 吗?还是保留用于端到端/组件测试?

最佳答案

Angular 文档说 您应该为管道和服务编写独立的单元测试。 独立的单元测试不需要 Testbed。 ( https://angular.io/guide/testing#isolated-unit-tests )
对于 Angular Components 测试,您很可能希望使用 Testbed,我仍将其视为单元测试。现在说到这里,我应该再次引用文档

Good developers write both kinds of tests for the same application part, often in the same spec file. Write simple isolated unit tests to validate the part in isolation. Write Angular tests to validate the part as it interacts with Angular, updates the DOM, and collaborates with the rest of the application.

希望对您有所帮助。

关于javascript - 我们应该在单元测试时使用 Angular TestBed 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47215273/

相关文章:

javascript - 根据更改选择获取替代数据值

没有 ng-template 的 Angular ngx-bootstrap 模型

typescript - 类型化事件系统

javascript - 如何将 Javascript 时间戳转换为 UTC 格式?

javascript - Bootstrap 模式适用于内页,但不适用于主页

angular - 如果在特定文件夹中,由 angular CLI 生成的测试将失败

javascript - 从其他组件访问激活的路由数据

TypeScript 推断接口(interface)实现类中的类型参数

javascript - JS regex - 如何将空格添加到我使用 RegExp 找到的符号

javascript - Ionic 2/Angular 2 中的 NPM 模块 "only refers to a type, but is being used as a value here."