angular.io icon indicating copy to clipboard operation
angular.io copied to clipboard

Error: Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule'

Open protagonist51 opened this issue 9 years ago • 2 comments

I'm getting error during creating Test component instance.

`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: [                 DomainCacheService,                 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 '); }); }); `

I'm getting Error: Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule' error. I notice that if I remove "fixture = TestBed.createComponent(TaskviewComponent);" error would be resolved.

protagonist51 avatar Dec 19 '16 09:12 protagonist51

You can't import 'NgModule' as it is a decorator not a module.

joshuawilson avatar Feb 15 '17 05:02 joshuawilson

Questions goes to SO.

Foxandxss avatar Apr 10 '17 14:04 Foxandxss