gpt4 book ai didi

angular - 模块 'StateService' 声明的意外值 'DynamicTestModule'

转载 作者:行者123 更新时间:2023-12-04 02:00:58 26 4
gpt4 key购买 nike

我在 Angular 5 项目中使用 UI Router。为页脚组件运行测试时出现此错误:

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

知道我哪里出错了吗?

最佳答案

declarations 数组仅适用于可声明的类:组件、指令和管道。将 StateService 添加到 providers 数组,如下所示:

TestBed.configureTestingModule({
imports: [],
declarations: [ FooterComponent ],
providers: [StateService]
})

关于angular - 模块 'StateService' 声明的意外值 'DynamicTestModule',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47289601/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com