简体   繁体   English

如何正确使用clr-nav-level修复spec.ts错误

[英]How to correctly use clr-nav-level to fix spec.ts error

I'm using Clarity and Angular for an application and I'm trying to add tests to it. 我正在为应用程序使用Clarity和Angular,并且试图向其添加测试。 But I keep getting this error whenever I try to run the test: 但是,每当尝试运行测试时,我都会不断收到此错误:

Can't bind to 'clr-nav-level' since it isn't a known property of 'div'

Do I have to import anything else from the Clarity library to make this work? 我是否需要从Clarity库中导入其他任何内容才能进行这项工作?

Here's my spec.ts code: 这是我的spec.ts代码:

describe('AppComponent', () => {
  let appComponent: AppComponent;
  let fixture: ComponentFixture<AppComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        ClarityModule,
        RouterTestingModule,
        BrowserAnimationsModule
      ],
      declarations: [
        AppComponent,
        NavbarComponent
      ]
    }).compileComponents();
    fixture = TestBed.createComponent(AppComponent);
    appComponent = fixture.debugElement.componentInstance;
  }));

  it('should create the app', async(() => {
    expect(appComponent).toBeTruthy();
  }));
});

Add this to your TestBed configuration: 将此添加到您的TestBed配置:

schemas: [ CUSTOM_ELEMENTS_SCHEMA ]

CUSTOM_ELEMENTS_SCHEMA Defines a schema that will allow: CUSTOM_ELEMENTS_SCHEMA定义一个架构,该架构将允许:

  • any non-Angular elements with a - in their name 名称中带有-的任何非Angular元素
  • any properties on elements with a - in their name which is the common rule for custom elements. 元素名称上带有-的任何属性,这是自定义元素的通用规则。

More info: https://angular.io/api/core/CUSTOM_ELEMENTS_SCHEMA 更多信息: https//angular.io/api/core/CUSTOM_ELEMENTS_SCHEMA

This will ignore all custom properties on your HTML elements. 这将忽略HTML元素上的所有自定义属性。

If this didn't resolve your issue please put your component code in the question. 如果这不能解决您的问题,请在问题中输入组件代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM