测试时无法导入ng-zorro-antd模块
我无法在单元测试中从 ng-zorro-antd 导入模块,但我可以构建应用程序而不会出现任何错误。我正在使用 Angular 12.2.4 和 ng-zorro-antd 12.1.1
我收到以下错误:
Error: Unexpected value 'NzButtonModule' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.
这是我的规范文件:
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import {NzButtonModule} from 'ng-zorro-antd/button';
import { AntViewComponent } from './ant-view.component';
describe('AntViewComponent', () => {
let component: AntViewComponent;
let fixture: ComponentFixture<AntViewComponent>;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [NzButtonModule],
declarations: [AntViewComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(AntViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeDefined();
});
});
我做错了什么吗?这很奇怪,因为我可以很好地运行应用程序,导入和使用 ng-zorro-antd 中的模块,但我不能在单元测试中。
I cannot import modules from ng-zorro-antd in unittests, but I can build the app without any error. I'm using Angular 12.2.4 and ng-zorro-antd 12.1.1
I get the following error:
Error: Unexpected value 'NzButtonModule' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.
Here my spec file:
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import {NzButtonModule} from 'ng-zorro-antd/button';
import { AntViewComponent } from './ant-view.component';
describe('AntViewComponent', () => {
let component: AntViewComponent;
let fixture: ComponentFixture<AntViewComponent>;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [NzButtonModule],
declarations: [AntViewComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(AntViewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeDefined();
});
});
Did I do something wrong? This is very weird since I can run the app fine, import and use the modules from ng-zorro-antd but I can't in unittests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用旧版本的 ng-zorro-antd 解决了该问题(12.0.1)。
Using an older version of ng-zorro-antd resolved the issue (12.0.1).