【发布时间】:2017-11-14 15:33:56
【问题描述】:
我在 Angular 5 项目中使用 UI 路由器。为页脚组件运行测试时,出现此错误:
Failed: Unexpected value 'StateService' declared by the module 'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.
但是,我正在导入 StateService,并将其包含在 TestBed 的声明数组中。
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FooterComponent } from './footer.component';
import { StateService } from '@uirouter/angular';
fdescribe('FooterComponent', () => {
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ StateService ],
declarations: [ FooterComponent ],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
知道我哪里出错了吗?
【问题讨论】:
标签: angular unit-testing karma-runner