DevExtremeを使ったコンポーネントのテストでエラー

ng g component で生成したコンポーネントで DevExtremeを使うと、デフォルトで生成されるテストでは下記のエラーが出る。

Failed: Template parse errors: 'dxo-common-series-settings' is not a known element: 
1. If 'dxo-common-series-settings' is an Angular component, then verify that it is part of this module. 
2. If 'dxo-common-series-settings' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 
(" <dx-chart> [ERROR ->]<dxo-common-series-settings type="bar"></dxo-common-series-settings> <dxo-size [height]="200"><"): ng:///DynamicTestModule/AnnualChartGridComponent.html@2:6

とりあえず schemas: [ NO_ERRORS_SCHEMA ] をつけてみるも、違うエラーが。

Failed: Template parse errors: Property binding dxTemplateOf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". (" [width]="600" [height]="400"> [ERROR ->]<div *dxTemplate="let data of 'content'"> <dx-data-grid [width]="560" [height]="300" "): ng:///DynamicTestModule/AnnualChartGridComponent.html@26:6

正解は下記のように TestingModule に DevExtremeModule を import することらしい。

    TestBed.configureTestingModule({
      declarations: [ AnnualChartGridComponent ],
      imports: [ DevExtremeModule ]
    })

これでエラーが消えてテストが書ける。

コメントを残す