【问题标题】:Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation模块“DynamicTestModule”导入的意外值“DecoratorFactory”。请添加@NgModule 注释
【发布时间】:2018-05-24 15:31:48
【问题描述】:

这是我的规范文件:

import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By }              from '@angular/platform-browser';
import { DebugElement }    from '@angular/core';
import { ScorecardComponent } from './scorecard.component';
import { DataService } from '../data.service';
import { HttpModule } from '@angular/http';
import { Component } from '@angular/core';

describe('ScorecardComponent', () => {

  let comp:    ScorecardComponent;
  let fixture: ComponentFixture<ScorecardComponent>;
  let de:      DebugElement;
  let el:      HTMLElement;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ ScorecardComponent ],
      imports: [ Component, HttpModule ],  
      providers: [ DataService ]  
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ScorecardComponent);
    comp = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(comp).toBeTruthy();
  });


});

我收到此错误:

模块导入的非预期值“DecoratorFactory” '动态测试模块'。请添加@NgModule 注解。

【问题讨论】:

  • 从导入数组中移除Component
  • 如果我从导入数组中删除组件,我得到以下错误-
  • 在此处删除 imports: [ Component, HttpModule ],
  • 如果我从导入数组中删除组件,我得到以下错误-失败:模板解析错误:没有将“exportAs”设置为“ngbDropdown”的指令
  • 改为导入NgbDropdownModule

标签: angular testing jasmine karma-runner


【解决方案1】:

如果你使用了 NgModule 并且缺少 NgModule 来导入,我们预计会出现这种错误。 所以如果你使用NgModule,请务必导入:"import {NgbModule} from '@ng-bootstrap/ng-bootstrap';"

【讨论】:

    猜你喜欢
    • 2022-10-13
    • 2020-05-07
    • 2021-10-07
    • 2020-12-27
    • 2019-07-12
    • 2019-02-06
    • 2017-10-23
    • 2017-05-07
    • 2018-01-10
    相关资源
    最近更新 更多