0
我正在嘗試使用Angular 2測試組件,但是在加載依賴時遇到問題。Angular 2測試依賴關係
當我試圖在測試UserShowcaseComponent
時嘗試導入UserModule
,並且如果我不導入它,我收到很多遺漏的組件錯誤。
測試設置是什麼角CLI生成和我的具體試驗如下
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { UserModule } from '../../user.module';
import { UserShowcaseComponent } from './user-showcase.component';
describe('UserShowcaseComponent',() => {
let component: UserShowcaseComponent;
let fixture: ComponentFixture<UserShowcaseComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [UserModule], <---------------------------------- NOTE
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UserShowcaseComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create',() => {
expect(component).toBeTruthy();
});
});
從因果報應的錯誤僅僅是這個(這是完整的輸出,沒有測試運行):
29 11 2016 16:49:40.478:INFO [karma]: Karma v1.2.0 server started at http://localhost:9876/
29 11 2016 16:49:40.479:INFO [launcher]: Launching browser Chrome with unlimited concurrency
29 11 2016 16:49:40.649:INFO [launcher]: Starting browser Chrome
29 11 2016 16:49:42.010:INFO [Chrome 53.0.2785 (Linux 0.0.0)]: Connected on socket /#Jpv1IioGnou6CQtUAAAA with id 98117142
Chrome 53.0.2785 (Linux 0.0.0) ERROR