【发布时间】:2016-01-27 14:49:08
【问题描述】:
我想在 Angular2 中的 hello world 应用程序上使用 typescript 编写规范进行 e2e 测试。但是,量角器崩溃并显示以下消息:
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: ReferenceError: System is not defined
at Object.<anonymous> (C:\Dev\d2ipm\test\e2e\overview.js:1:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at C:\Users\%username%\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine\lib\jasmine.js:63:5
at Array.forEach (native)
at Jasmine.loadSpecs (C:\Users\%username%\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine\lib\jasmine.js:62:18)
[launcher] Process exited with error code 100
由于我默认使用 Angular2 建议的 SystemJS,System 包含在每个编译的 .js 文件中,包括测试规范。我的 index.html 按照教程中的建议配置系统,并且该应用程序可以正常工作:
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
},
globalEvaluationScope: false
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
运行用纯 JS 编写的测试可以正常工作。如何让我的测试环境看到System?
【问题讨论】:
-
在测试教程中他们使用 CommonJS 而不是 System.他们使用 Jasmine,因为我看到 Protractor 不是为 Angular 2 完成的,是吗?
-
@Langley 测试教程涉及单元测试,而不是 e2e。量角器也使用茉莉花。 Angular2 在存储库中有量角器配置,所以他们似乎不会在 2.0 版中使用它。
-
我知道它使用 Jasmine,但它是为 Angular 1 构建的,我还没有为 Angular 2 找到它。
-
@Langley 你对使用 Angular2 有什么建议?
-
好吧,我相信量角器是建立在 Selenium 之上的,所以也许这可以解决问题。我,我会等他们制作一个新的量角器。
标签: angular typescript protractor e2e-testing