OnPush
変更検出ストラテジでコンポーネントをテストする際に問題があります。角度2のOnPushコンポーネントのテスト
テストは、私はそれが期待どおりに動作Default
戦略を使用している場合、この
it('should show edit button for featured only for owners',() => {
let selector = '.edit-button';
component.isOwner = false;
fixture.detectChanges();
expect(fixture.debugElement.query(By.css(selector))).toBeFalsy();
component.isOwner = true;
fixture.detectChanges();
expect(fixture.debugElement.query(By.css(selector))).toBeTruthy();
});
のようになりますが、OnPush
でisOwner
への変更はdetectChanges
への呼び出しによって再レンダリングされていません。何か不足していますか?
このスレッドを見てくださいhttps://github.com/angular/angular/issues/12313ここであなたのテストはhttps://plnkr.co/edit/llJG17sBZZUXXBertYPp?p=preview – yurzui