【问题标题】:Angular 2 unit testing with VMware Clarity modules使用 VMware Clarity 模块进行 Angular 2 单元测试
【发布时间】:2017-08-18 04:53:33
【问题描述】:

我正在为使用 VMware 的 Clarity 组件的 angular 2 项目做 POC。当我运行测试运行器时,出现以下错误:

'clr-main-container' is not a known element:
1. If 'clr-main-container' is an Angular component, then verify that it is part of this module.
2. If 'clr-main-container' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<clr-main-container>

我是 Angular 2 的新手,在 Google 上找不到任何东西。

【问题讨论】:

  • 嗨@agillette。您似乎还没有注册ClarityModule。需要更多细节来理解完整的问题。什么是测试运行器?您在使用 Clarity 种子项目吗?我建议浏览 Clarity 入门页面:vmware.github.io/clarity/get-started#seedProjectClarity 并使用他们的种子应用程序。

标签: angular unit-testing vmware-clarity


【解决方案1】:

agillette, 您可能在测试中缺少 Testbed 配置。比如:

import {async, ComponentFixture, TestBed} from "@angular/core/testing";
import {ClarityModule} from 'clarity-angular';

describe('...', function() {

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [ClarityModule.forRoot()],
      declarations: [YourTestComponent]
    });
  });

});

您可以阅读有关 TestBed 的更多信息here

还可以随时查看Clarity seed,了解一个简单的工作应用程序,其中包含测试连接。

【讨论】:

    猜你喜欢
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多