Javascript 如何在 Angular 2 中使用量角器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33541103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:12:47  来源:igfitidea点击:

How to use Protractor with Angular 2?

javascripttestingmigrationprotractorangular

提问by JohnnyC

I use Protractor with Angular 1.x. I would like to migrate to Angular 2.0 step by step but I don't see Protractor in the docs.

我在 Angular 1.x 中使用量角器。我想逐步迁移到 Angular 2.0,但我在文档中没有看到量角器。

Has protractor been dropped since Angular 2? Should I write my tests without using Protractor, using Jasmine instead (or others)?

自 Angular 2 以来量角器是否已被删除?我应该在不使用 Protractor 的情况下编写测试,而是使用 Jasmine(或其他)?

采纳答案by alecxe

You can test Angular 2 applications with Protractor(starting from Protractor 2.5.0).

您可以使用Protractor(从 Protractor 2.5.0 开始)测试 Angular 2 应用程序

For Protractor 5.0.0+, you don't have to do anything specific, Protractor will auto-detect the Angular version used in the application under test.

对于Protractor 5.0.0+,您无需执行任何特定操作,Protractor 将自动检测被测应用程序中使用的 Angular 版本

For Protractor >= 2.5.0 and <= 4.0.14, you would only need to add useAllAngular2AppRoots: trueto your config. Here is a sample.

对于 Protractor >= 2.5.0 和 <= 4.0.14,您只需要添加useAllAngular2AppRoots: true到您的配置中。这是一个示例



Note that several built-in Protractor matchers would not yet work with Angular2, see:

请注意,几个内置的量角器匹配器还不能与 Angular2 一起使用,请参阅:

There is also that Protractor+Angular2 problem in Firefox (still unresolved), see:

Firefox 中也存在 Protractor+Angular2 问题(仍未解决),请参阅: