由模块“DynamicTestModule”导入的意外值“DecoratorFactory”。请添加@NgModule 注释

suh*_*uha 5 testing jasmine karma-runner angular

这是我的规范文件:

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


});
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

由模块“DynamicTestModule”导入的意外值“DecoratorFactory”。请添加@NgModule 注释。

小智 0

如果您使用了 NgModule 并且缺少 NgModule 来导入,我们预计会出现此类错误。因此,如果您正在使用 NgModule,请确保导入它:"import {NgbModule} from '@ng-bootstrap/ng-bootstrap';"