失败:模块 'DynamicTestModule' 导入了意外值 'TreeviewConfig'。请在单元测试中添加@NgModule 注解
Failed: Unexpected value 'TreeviewConfig' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation in unit test
我正在尝试测试包含 ngx-treeview 的组件。我写了下面的测试,但它失败了,标题中包含错误消息(显然除了单元测试部分):
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { TreeviewConfig, TreeviewItem, TreeviewModule } from 'ngx-treeview';
import { TabTreeviewComponent } from './tab-treeview.component';
describe('TabTreeviewComponent', () => {
let component: TabTreeviewComponent;
let fixture: ComponentFixture<TabTreeviewComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ TabTreeviewComponent ],
imports: [ TreeviewConfig, TreeviewItem, TreeviewModule.forRoot() ],
providers: [ ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TabTreeviewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
const config = TreeviewConfig.create({
hasAllCheckBox: false,
hasFilter: true,
hasCollapseExpand: true,
maxHeight: 435
});
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
我已经尝试将 TreeviewConfig 初始化为声明,显然没有任何效果。我还尝试将它作为提供者提供 - 这也没有任何帮助......我不确定此时我还能尝试什么,TestBed 必须有办法以某种方式包含 TreeView 的配置,或者我是否在做一个合乎逻辑的这里是谬论?
抛出错误是因为您在 inports
数组
中包含了非模块
基本上只需要导入TreeviewModule
imports: [ TreeviewModule.forRoot() ],
我正在尝试测试包含 ngx-treeview 的组件。我写了下面的测试,但它失败了,标题中包含错误消息(显然除了单元测试部分):
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { TreeviewConfig, TreeviewItem, TreeviewModule } from 'ngx-treeview';
import { TabTreeviewComponent } from './tab-treeview.component';
describe('TabTreeviewComponent', () => {
let component: TabTreeviewComponent;
let fixture: ComponentFixture<TabTreeviewComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ TabTreeviewComponent ],
imports: [ TreeviewConfig, TreeviewItem, TreeviewModule.forRoot() ],
providers: [ ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TabTreeviewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
const config = TreeviewConfig.create({
hasAllCheckBox: false,
hasFilter: true,
hasCollapseExpand: true,
maxHeight: 435
});
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
我已经尝试将 TreeviewConfig 初始化为声明,显然没有任何效果。我还尝试将它作为提供者提供 - 这也没有任何帮助......我不确定此时我还能尝试什么,TestBed 必须有办法以某种方式包含 TreeView 的配置,或者我是否在做一个合乎逻辑的这里是谬论?
抛出错误是因为您在 inports
数组
基本上只需要导入TreeviewModule
imports: [ TreeviewModule.forRoot() ],