【问题标题】:Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule' - karma-jasmine模块“DynamicTestModule”导入的意外值“DecoratorFactory” - karma-jasmine
【发布时间】:2017-05-07 18:06:22
【问题描述】:

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

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 ');
});
});

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

【问题讨论】:

    标签: angular karma-jasmine angular2-testing


    【解决方案1】:

    你不能导入“NgModule”,因为它是一个装饰器而不是一个模块。

    【讨论】:

    • 如果你在 Angular 和 Emmet 上使用 Bootstrap 4,Emmet 可能已经自动填充了 NgModule 并且你接受了它而不是 NgbModule。如您所见,它们的拼写很接近,因此可能会发生。这就是我所做的,我想我会分享以防其他人有这个问题。
    猜你喜欢
    • 2020-01-06
    • 2018-05-24
    • 2020-11-23
    • 2017-06-03
    • 2021-06-19
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多