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. ("<ons-navigator [ERROR ->][page]="initialPage"></ons-navigator>"): 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();
}));
メッセージに書いてある通りって言えば、それまでなんですが、小ネタという事で。