【发布时间】:2017-07-02 02:44:18
【问题描述】:
在为我的 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 添加到我的根模块以及所有其他模块,但我仍然收到错误。
- 我还需要做什么?
- 这需要在所有模块中,还是只在根目录中?
- 还有什么需要补充的吗?
【问题讨论】:
-
在所有模块中,您有一个包含“-”的选择器的组件。
-
是的,正如我上面提到的,我已经这样做了。我已将此添加到我的所有模块中。仍然收到错误。
-
您已将架构:[CUSTOM_ELEMENTS_SCHEMA] 添加到您的 TestBed.configureTestingModule?
-
我不相信我有那个模块。我需要拥有它吗?
-
是的,这里有:angular.io/docs/ts/latest/api/core/testing/index/… 还可以查看与使用 ngModules 进行测试相关的文档:angular.io/docs/ts/latest/guide/testing.html#!#testbed
标签: javascript unit-testing angular typescript