0

我正在将 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();
  }));
});
4

1 回答 1

0

将此添加到您的 TestBed 配置中:

schemas: [ CUSTOM_ELEMENTS_SCHEMA ]

CUSTOM_ELEMENTS_SCHEMA 定义一个允许:

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

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

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

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

于 2018-03-20T03:38:35.877 回答