2016-08-23 72 views
0

是否有任何有關如何在Angular 2最新版本中注入依賴關係的指令或示例設置?在Angular 2的單元測試中注入依賴關係2.0.0-rc.5

The Testing Guide仍然不完整,只會帶你到目前爲止。例如,如果你想測試一個採用@Input()參數的組件,我的理解是你特別需要注入它,但是我遇到了一些讓它工作的問題。

當我嘗試關注例如this one時,我收到有關configureCompiler不屬於@angular/core/testing的錯誤。我相信這個may have been moved into TestBed,但是當我嘗試使用調用TestBed.createComponent(MyComponent)時出現錯誤,表明有No provider for TestingCompilerFactory!而當我嘗試從@angular/compiler/testing導入它時,出現Typescript編譯器錯誤,它不存在。做一個grep,我可以找到它在我的本地node_nodiles中的文件,但如果我嘗試導入它,那麼該文件會給出一大堆Typescript錯誤!

有沒有關於如何做到這一點的簡單指南?

回答

2

在RC5中進行測試可能很困難,因爲它仍然如此新穎。你可以看看這個angular2-starter(https://github.com/antonybudianto/angular2-starter),看看他是如何在RC5中實現測試的。

+0

另一個例子稍微簡潔:https://github.com/juliemr/ng2-test-seed/blob/master/src/test/greeting-component_test.ts – Dave