javascript - "CUSTOM_ELEMENTS_SCHEMA"Angular 2 App 测试错误

标签 javascript unit-testing angular typescript

在为我的 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/

相关文章:

javascript - ngx-translate 和 ngx-i18next 有什么区别

javascript - 从具有 ngIf 指令的输入中获取值时出错

javascript - 在选择下拉列表中显示嵌套的 json

javascript - 错误: [$injector:unpr]

javascript - 类型 'opacity' 上不存在属性 'IntrinsicAttributes',React Native 中 View 不透明度引发抛出和错误

javascript - 使用 Jest 测试 ES6 类时出现问题

java - 如何模拟兼容apache common的ServletFileUpload的HTTP请求?

node.js - 为什么多次调用 jest mockResolvedValueOnce 返回相同的值?

javascript - 解析 Facebook 登录错误 : "You must initialize FacebookUtils before calling logIn"

javascript - 数组中 JavaScript 展开语法的时间复杂度是多少?