【发布时间】:2020-05-30 08:58:51
【问题描述】:
我已经在我的 spec.ts 中导入了角度材料,但是在尝试运行该特定组件的 ng 测试时出现以下错误:
错误:模板解析错误:
'mat-form-field' 不是已知元素: 1. 如果 'mat-form-field' 是 Angular 组件,则验证它是否是该模块的一部分。 2. 如果“mat-form-field”是一个 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。 ("
[错误->] ][dataSource]="parts" matSort class="mat-elevation-z8"> "): ng:///DynamicTestModule/PartViewComponent.html@6:23 找不到管道“uuidAbbrev”(“eader-cell *matHeaderCellDef mat-sort-header>Uuid {{[错误 ->]row.uuid|uuidAbbrev}} "): ng:///DynamicTestModule/PartViewComponent.html@10:44 无法绑定到“matHeaderRowDef”,因为它不是“tr”的已知属性。 (" ]matHeaderRowDef="displayedProps"> [错误->] ]*matRowDef="让行;列:displayedProps;"> "): ng:///DynamicTestModule/PartViewComponent.html@24:35 嵌入式模板上的任何指令均未使用属性绑定 matRowDefColumns。确保属性名称拼写正确,并且所有指令都列在“@NgModule.declarations”中。 (" [错误->] http://localhost:9876/_karma_webpack_/vendor.js:36418:17) 在 TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (http://localhost:9876/_karma_webpack_/vendor.js:54593:19) 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (http://localhost:9876/_karma_webpack_/vendor.js:60159:37) 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (http://localhost:9876/_karma_webpack_/vendor.js:60146:23) 在http://localhost:9876/_karma_webpack_/vendor.js:60089:62 在 Set.forEach() 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (http://localhost:9876/_karma_webpack_/vendor.js:60089:19) 在http://localhost:9876/_karma_webpack_/vendor.js:60007:19 在 Object.then (http://localhost:9876/_karma_webpack_/vendor.js:36409:77) 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndAllComponents (http://localhost:9876/_karma_webpack_/vendor.js:60005:26) ```
【问题讨论】:
-
分享一些代码,你的测试是什么样的?
-
添加了所有需要的细节:1.我的测试文件(spec.ts)2.要测试的component.ts文件3.执行测试用例时遇到的错误。
-
我相信您需要将材料组件模块添加到
TestBed.configureTestingModule()中的导入数组中 -
测试用例还在继续。您能帮我为上述编写的 .ts 文件提供一个有效的测试用例吗?
标签: angular unit-testing karma-jasmine