angular - ng test = 很多“验证它是这个模块的一部分”错误
问题描述
我正在尝试编写 Jasmine 单元测试,但是当我运行 ng test 时,终端因错误而疯狂
示例错误
1. If 'mat-radio-group' is an Angular component, then verify that it is part of this module.
2. If 'mat-radio-group' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("has-error">
<span id="over21Label">Are you over the age of 21?</span>
[ERROR ->]<mat-radio-group aria-label="Select an option" name="over21" formControlName="over21">
"): ng:///DynamicTestModule/BuyerSignupComponent.html@118:14
'mat-card' is not a known element:
1. If 'mat-card' is an Angular component, then verify that it is part of this module.
2. If 'mat-card' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
<div class="row">
<div class="col-md-6 col-sm-8 col-lg-3 mx-auto">
[ERROR ->]<mat-card id="signupBox">
"): ng:///DynamicTestModule/BuyerSignupComponent.html@14:10unt Registration</div>
对于 mat-icon、mat-placeholder 等还有其他类似的错误...
我的 app.module 文件正在导入这些。当我发现类似的带有此类错误的 stackoverflow 帖子时,答案是在 app.module 中导入它们,但它们已经是。我是这样导入的
import {
MatInputModule,
MatCardModule,
MatButtonModule,
MatToolbarModule,
MatExpansionModule,
MatRadioModule,
MatStepperModule,
MatCheckboxModule,
MatSidenavModule,
MatSnackBarModule,
MatIconModule,
MatDialogModule,
MatListModule,
MatDividerModule,
MatSelectModule,
MatProgressSpinnerModule,
MatAutocompleteModule,
MatTableModule,
MatRippleModule,
MatTooltipModule
} from "@angular/material";
然后在进口
],
imports: [
MatRadioModule, MatCardModule, etc...
所以它正在被导入,所以我做错了什么?
解决方案
您需要将其作为导入添加到您的测试模块 (mycomponent.component.spec.ts)
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [MyCmponent],
}).compileComponents();
}));
推荐阅读
- excel - Excel 停止在后台打开工作簿中的工作表计算
- reactjs - TypeError:this.props.getRecipes 不是函数
- c# - Azure Blob 存储读取时间非常慢
- java - 假人头声明
- ios - 如何删除 NavigationView 顶部的填充?
- ios - Firebase Crashlytics 为 UUID 上传丢失的 dSYMs 文件
- python - conda 命令无法执行,因为它无法读取整个用户路径
- json - Youtube-dl - 提取元数据/json 信息到文本文件
- python - 如何从外部边界框中找到重叠和内部边界框?
- html - 调整大小时html表格打破背景