我用 angular-cli 创建了一个新项目( ng new my-project-name
)
当我运行 npm run test
它运行时没有任何故障。
我在我的项目中添加了 font-awsome 模块( https://www.npmjs.com/package/angular-font-awesome )来显示字体图标。
在我的 html 文件中添加了 <fa name="bars"></fa>
标签并按预期输出。如果我再次运行 npm run test
它以 3 次失败结束,所有这些都针对 fa
标签。
这是样本失败报告
'fa' is not a known element:
1. If 'fa' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center"> [ERROR ->]<fa name="bars"></fa>
<h1> Welcome to {{title}}!
"): ng:///DynamicTestModule/AppComponent.html@2:2 Error: Template parse errors:
at syntaxError home/harsha/Documents/Projects/testProject/node_modules/@angular/compiler/esm5/compiler.js:466:22)
我尝试了一些修复,例如在 app.module.ts
文件中添加 NO_ERRORS_SCHEMA
, CUSTOM_ELEMENTS_SCHEMA
--- 。
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AngularFontAwesomeModule
],
providers: [],
bootstrap: [AppComponent],
schemas: [
CUSTOM_ELEMENTS_SCHEMA,
NO_ERRORS_SCHEMA
]
})`
但没有任何效果。
原文由 Harsha Vardhan Putrevu 发布,翻译遵循 CC BY-SA 4.0 许可协议
请不要使用
NO_ERRORS_SCHEMA
对于这种简单的场景,如果组件工作正常并且测试错过了fa
组件,那么您还需要添加AngularFontAwesomeModule
到您的 TestBed 导入。