2016-10-13 14 views
16

Tôi gặp sự cố khi thử nghiệm app.component.ts trong Angular 2. Tôi đang sử dụng angular-cli. Bất cứ khi nào tôi chạy thử nghiệm ng, app.component.spec.ts của tôi làm cho giao diện điều khiển nhanh chóng với các lỗi:Góc 2.0.0 - Thử nghiệm "được nhập bởi mô-đun 'DynamicTestModule'"

Failed: Unexpected directive 'HomeModuleComponent' imported by the module 'DynamicTestModule' 
Error: Unexpected directive 'HomeModuleComponent' imported by the module 'DynamicTestModule' 

tôi nhập khẩu các HomeModuleComponent trong Testbed

TestBed.configureTestingModule({ 
    declarations: [AppComponent], 
    imports : [ HomeModuleComponent ] 
}); 

bất cứ ai có thể giúp tôi với vấn đề này?

+3

Tôi nghĩ rằng tôi đã tìm thấy vấn đề như bây giờ. HomeModuleComponent phải nằm trong các khai báo không có trong hàng nhập khẩu. Hơn nữa, bạn có thể nhập một Module trong TestBed của bạn? Cảm ơn. – xiotee

Trả lời

17

HomeModuleComponentComponent không phải là Module, vì vậy nó phải được khai báo:

TestBed.configureTestingModule({ 
    declarations: [AppComponent, HomeModuleComponent], 
    imports : [ ] 
}); 

và sau đó bạn có thể tạo các thành phần để kiểm tra là,

TestBed.createComponent(AppComponent); 
Các vấn đề liên quan