在为我的 Angular 2 应用程序编写测试时,我遇到了这些错误:我们正在使用的选择器:
"): AppComponent@12:35 'tab-view' is not a known element:
1. If 'my-tab' is an Angular component, then verify that it is part of this module.
2. If 'my-tab' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
</div>
<div class="app-body">
[ERROR ->]<tab-view class="my-tab" [options]="tabOptions"></tab-view>
</div> </div>
我已经添加了 CUSTOM_ELEMENTS_SCHEMA
到我的根模块,以及所有其他模块,但我仍然收到错误。
- 我还需要做什么?
- 这需要在所有模块中,还是只在根模块中?
- 还有什么我需要补充的吗?
最佳答案
所以我必须做的是让这个工作在 TestBed.configureTestingModule 中设置模式 - 这不是一个单独的模块文件,而是 app.component.spec.ts 文件的一部分。感谢@camaron小费。我确实认为文档在这一点上可能更清楚。
无论如何,这是我添加的,以使其正常工作。这是我的 app.component.spec.ts 文件的打开内容。
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './../app.component';
import { RouterTestingModule } from '@angular/router/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
describe('AppComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
declarations: [AppComponent],
imports: [RouterTestingModule]
});
TestBed.compileComponents();
});
关于javascript - "CUSTOM_ELEMENTS_SCHEMA"Angular 2 App 测试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42215500/