繁体   English   中英

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

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

我正在为应用程序使用Clarity和Angular,并且试图向其添加测试。 但是,每当尝试运行测试时,我都会不断收到此错误:

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

我是否需要从Clarity库中导入其他任何内容才能进行这项工作?

这是我的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();
  }));
});

将此添加到您的TestBed配置:

schemas: [ CUSTOM_ELEMENTS_SCHEMA ]

CUSTOM_ELEMENTS_SCHEMA定义一个架构,该架构将允许:

  • 名称中带有-的任何非Angular元素
  • 元素名称上带有-的任何属性,这是自定义元素的通用规则。

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

这将忽略HTML元素上的所有自定义属性。

如果这不能解决您的问题,请在问题中输入组件代码。

暂无
暂无

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

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