私は2つのコンポーネントを使用しています。Angular2テスト - 失敗:未知(約束):エラー:テンプレート解析エラー:「メッセージ」にはバインドできません
まず一つがある:含まれているhtmlファイルあり"GamePanelComponent"
: "my-game-panel-output"
タグを
2つ目は、次のとおりです。私は、テストを書いた
import { Component, Input } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-game-panel-output',
templateUrl: 'gamepaneloutput.component.html',
styleUrls: [ 'gamepaneloutput.component.css' ]
})
export class GamePanelOutputComponent {
@Input()
message: string;
}
GamePanelComponent
へ: import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { GamePanelComponent } from './gamepanel.component';
import { GamePanelOutputComponent } from '../gamepaneloutput/gamepaneloutput.component';
describe('GamePanelComponent (inline template)',() => {
let comp: GamePanelComponent;
let fixture: ComponentFixture<GamePanelComponent>;
beforeEach(async (() => {
TestBed.configureTestingModule({
declarations: [ GamePanelComponent ], // declare the test component
}).compileComponents()
.then(() => {
fixture = TestBed.createComponent(GamePanelComponent);
comp = fixture.componentInstance;
});
}));
it('isValidMove',() => {
comp.ngOnInit();
let isValid = comp.isValidMove(0,0);
expect(isValid).toBe(false);
});
});
残念ながら、このエラーでテストは失敗します:
Failed: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'message' since it isn't a known property of 'my-game-panel-output'.
ご覧のとおり、「GamePanelOutputComponent
」をインポートしようとしましたが、それは役に立ちません。
私は本当にそれに固執しています。 誰かを助けることができますか?
あなたはさらに説明することができますか? – ohadinho
私は答えを更新しました。それはあなたに今より明らかですか? –
GamePanelOutputComponentカスタムhtml要素を使用するために、何も\を宣言する必要はありませんでしたが、GamePanelOutputComponentをテストするためにGamePanelOutputComponentをインポートする必要がありますか? – ohadinho