aby*_*e85 3 unit-testing karma-runner angular
我在 Angular 5 项目中使用 UI Router。当运行页脚组件的测试时,我收到此错误:
Failed: Unexpected value 'StateService' declared by the module 'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.
Run Code Online (Sandbox Code Playgroud)
但是,我正在导入 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();
});
});
Run Code Online (Sandbox Code Playgroud)
知道我哪里出错了吗?
声明数组仅适用于可声明的类:组件、指令和管道。将StateService添加到提供者数组中,如下所示:
TestBed.configureTestingModule({
imports: [],
declarations: [ FooterComponent ],
providers: [StateService]
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4007 次 |
| 最近记录: |