- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我用 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)
我尝试了一些修复,例如添加 NO_ERRORS_SCHEMA
, CUSTOM_ELEMENTS_SCHEMA
在app.module.ts
文件。
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AngularFontAwesomeModule
],
providers: [],
bootstrap: [AppComponent],
schemas: [
CUSTOM_ELEMENTS_SCHEMA,
NO_ERRORS_SCHEMA
]
})`
但没有任何效果。
最佳答案
在您的测试规范文件中,它需要像这样设置:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ yourcomponent ],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
请注意 TestBed.configureTestingModule 方法中的 schemas 属性。设置 schemas 属性后,您的测试应该像添加 Font Awsome 组件之前一样正常运行。
关于angular - 要允许任何元素,请将 'NO_ERRORS_SCHEMA' 添加到此组件的 '@NgModule.schemas'。在 Angular 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47566743/
我正在编写我的第一个 Angular 测试,但在这里遇到了问题。我正在测试一个组件,其中有一个自定义属性 ... Official documentation说 The NO_ERRORS_SCH
在测试包含子组件的组件时,您有几种选择: 导入设置组件和子组件的模块。问题是您实例化了真正的子组件及其依赖项。 模拟子组件。这可能很乏味,具体取决于它有多少子组件。 使用 NO_ERRORS_SCHE
我有 Angular Popup Component 使用如下(Online Example): Menu Item 1
我有有效的 Angular 测试设置。当我测试内部嵌套组件的组件时,这会给我错误,这就是为什么我需要模拟这些组件。 Angular 测试文档向我们展示了模拟组件的其他方法 - 使用 NO_ERRORS
我有有效的 Angular 测试设置。当我测试内部嵌套组件的组件时,这会给我错误,这就是为什么我需要模拟这些组件。 Angular 测试文档向我们展示了模拟组件的其他方法 - 使用 NO_ERRORS
我有一些 Angular (v6) 组件,其模板包含 RouterLink 引用。这些组件具有默认生成的名为“should create”的测试用例,它因错误而中断: Can't bind to 'r
我用 angular-cli 创建了一个新项目(ng new my-project-name) 当我运行 npm run test它运行没有任何故障。 我在我的项目中添加了 font-awsome 模
我是一名优秀的程序员,十分优秀!