9 testing typescript angular-material angular
我创建此代码来测试我的组件.
我试过这段代码:
describe('Component: AddAlarms', () => {
let component: AddAlarmsFormComponent;
let fixture: ComponentFixture<AddAlarmsFormComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AddAlarmsFormComponent]
});
fixture = TestBed.createComponent(AddAlarmsFormComponent);
component = fixture.componentInstance;
});
});
Run Code Online (Sandbox Code Playgroud)
运行时ng test
显示此错误:
Failed: Template parse errors:
'mat-checkbox' is not a known element:
1. If 'mat-checkbox' is an Angular component, then verify that it is part of this module.
2. If 'mat-checkbox' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
</div>
<div class="input-field col s2">
[ERROR ->]<mat-checkbox class="example-margin" (click)="sortbydate()">Dates</mat-checkbox>
</div>
"): ng:///DynamicTestModule/NotificationsComponent.html@12:10
Run Code Online (Sandbox Code Playgroud)
我验证了我的module.ts,没关系.所以,我有这个:
import {MatCheckboxModule} from '@angular/material/checkbox';
Run Code Online (Sandbox Code Playgroud)
你能问我,问题是什么?
San*_*nde 18
您需要像imports
上面declarations
这样添加数组:
像这样添加:
import { MatCheckboxModule } from '@angular/material/checkbox';
Run Code Online (Sandbox Code Playgroud)
并添加如下imports
数组:
TestBed.configureTestingModule({
imports: [
MatCheckboxModule
],
declarations: [AddAlarmsFormComponent]
})
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10008 次 |
最近记录: |