一旦添加ng材料,angular5组件单元测试即被破坏
我在组件模板中使用角度材质,例如一旦添加ng材料,angular5组件单元测试即被破坏,angular,angular-material,angular5,Angular,Angular Material,Angular5,我在组件模板中使用角度材质,例如 <mat-list role="list"> <mat-list-item role="listitem"> <div class='title'> <h3 mat-header color="primary">Loign (admin/admin or user/user)</h3> </div> Loign(管理员/管理
<mat-list role="list">
<mat-list-item role="listitem">
<div class='title'>
<h3 mat-header color="primary">Loign (admin/admin or user/user)</h3>
</div>
Loign(管理员/管理员或用户/用户)
然后在我的组件单元测试中
describe('LoginComponent', ()=>{
let component:LoginComponent;
let fixture:ComponentFixture<LoginComponent>;
beforeEach(async()=>{
TestBed.configureTestingModule({
declarations:[LoginComponent]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
description('LoginComponent',()=>{
let组件:LoginComponent;
let夹具:组件夹具;
beforeach(异步()=>{
TestBed.configureTestingModule({
声明:[登录组件]
}).compileComponents();
});
在每个之前(()=>{
fixture=TestBed.createComponent(LoginComponent);
组件=fixture.componentInstance;
fixture.detectChanges();
});
但是,uni测试立即中断,如下所示:
[ERROR ->]<mat-list-item role="listitem">
<button (click)="login()" mat-raised-button color="primary" "): ng:///DynamicTestModule/LoginComponent.html@23:4
'mat-list' is not a known element:
1. If 'mat-list' is an Angular component, then verify that it is part of this module.
2. If 'mat-list' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
[错误->]
测试任何组件
时,必须在测试规范文件中导入所有必要的模块
,这些模块由被测组件
使用
我建议您在测试规范中导入新添加的角度材料模块。您需要在规范中导入与普通文件相同的模块。这适用于所有角度组件,而不仅仅是材料组件