4

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: [
                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. but this will not create the Test Component. Also, I notice that if I don't include NgModule in imports[], elements like Ngmodel, datepicker etc.are not recognized.

Protagonist
  • 1,649
  • 7
  • 34
  • 56

1 Answers1

1

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

Joshua Wilson
  • 2,546
  • 1
  • 20
  • 28
  • If you are using Bootstrap 4 for Angular and Emmet, Emmet may have autopopulated NgModule and you accepted it instead of NgbModule. As you can see they are close in spelling so it can happen. This is what I did, thought I'd share in case some else has this issue. – haakon.io Dec 01 '17 at 15:55