LoginSignup
0
0

More than 3 years have passed since last update.

onsenui(angular2+)で、Test(karma)で、Template parse errorsになった時の対応

Posted at

Angular(V.7)でプロジェクト作成し、Onsen-uiのDocumentの通りに、ons-naviを実装。

See: https://ja.onsen.io/v2/guide/angular2/#angular-2

app.component.htmlは、下記内容。このコンポーネント対象に単体テストしたい。

<ons-navigator [page]="initialPage"></ons-navigator>

karmaでテスト実行すると、ons-navigator, ons-pageなんて知らないといわれる。

Failed: Template parse errors:
Can't bind to 'page' since it isn't a known property of 'ons-navigator'.
1. If 'ons-navigator' is an Angular component and it has 'page' input, then verify that it is part of this module.
2. If 'ons-navigator' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("&lt;ons-navigator [ERROR -&gt;][page]="initialPage"&gt;&lt;/ons-navigator&gt;"): ng:///DynamicTestModule/AppComponent.html@0:15
'ons-navigator' is not a known element:
1. If 'ons-navigator' is an Angular component, then verify that it is part of this module.
.
.
.

で、上記のメッセージの「2. add 'CUSTOM_ELEMENTS_SCHEMA'」 してやる。

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

TestBedの構成時に、schemasを追加。

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [
        AppComponent
      ],
      schemas: [
        CUSTOM_ELEMENTS_SCHEMA,
      ],
    }).compileComponents();
  }));

メッセージに書いてある通りって言えば、それまでなんですが、小ネタという事で。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0