簡體   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