意想不到的价值' DecoratorFactory'由模块导入' DynamicTestModule' - karma-jasmine

时间:2016-12-22 07:15:47

标签: angular karma-jasmine angular2-testing

我在创建测试组件实例时遇到错误。

let comp: TaskviewComponent;
let fixture: ComponentFixture;
let deTaskTitle: DebugElement;
let elSub: HTMLElement;

describe('TaskviewComponent', () => {

    beforeEach( () => {
        TestBed.configureTestingModule({
            declarations: [
                TaskviewComponent
            ],
            imports: [
                NgModule,
                RouterTestingModule,
                TranslateModule.forRoot(),
            ],
            providers: [
                RestDataService,
                Restangular,
            {provide: OAuthService, useClass: OAuthServicMock},
            {provide: ComponentFixtureAutoDetect, useValue: true},
            {provide: UserInfoService, useClass: UserInfoServiceMock},
            {
                provide: LocalStorageService, //provide: LOCAL_STORAGE_SERVICE_CONFIG,
                useValue: {
                    prefix: ApplicationConstants.ANGULAR2_LOCAL_STORAGE_ID,
                    storageType: 'sessionStorage'
                }
            }],,

    })
            fixture = TestBed.createComponent(TaskviewComponent);
            comp = fixture.componentInstance;
            deTaskTitle = fixture.debugElement.query((By.css('.Subject')));
            elSub = deTaskTitle.nativeElement;

});

it('should have a subject', () => {
     expect(elSub.textContent).toContain('Client Data Maintenance2 ');
});
});

我收到错误:意外的价值' DecoratorFactory'由模块导入' DynamicTestModule'错误。我注意到,如果我删除" fixture = TestBed.createComponent(TaskviewComponent);"错误将得到解决。但这不会创建测试组件。此外,我注意到如果我不在导入[]中包含NgModule,则无法识别Ngmodel,datepicker等元素。

1 个答案:

答案 0 :(得分:1)

您无法导入" NgModule"因为它是装饰者而不是模块。