首页 > 解决方案 > 如何在 Angular 应用程序的量角器测试中使用 NgZone

问题描述

我们有一个 Angular 应用程序,它使用一个运行时间很长的 HTTP 请求来等待来自服务器的事件。使用 Protractor 进行测试时,所有相关文章(例如:https://valor-software.com/articles/testing-with-protractor-how-to-fix-synchronization-issues.html和此处:https ://jarifibrahim。 github.io/blog/protractor-and-page-synchronization/)建议在 Angular 区域之外运行检查,否则 Protractor 会等待长 HTTP 请求完成并最终超时。但是,我不清楚,因为我还没有找到与此相关的完整 e2e 测试,如何在典型的 Angular Protractor 测试中注入 NgZone,包括一个页面对象和一个测试 (.spec.ts) 文件,如此处所述:https://coryrylan.com/blog/introduction-to-e2e-testing-with-the-angular-cli-and-protractor。我尝试以典型的 Angular 组件方式在 Page Object 类构造函数中导入 NgZone constructor(private ngZone: NgZone),但这不起作用。我错过了什么?

标签: angularprotractor

解决方案


推荐阅读