refactor(ivy): ViewRef needs embededViewRef declaration (#33074)

PR Close #33074
This commit is contained in:
Miško Hevery
2019-10-09 16:58:01 -07:00
committed by Kara Erickson
parent f1ffd57105
commit 5632424d04
6 changed files with 83 additions and 33 deletions

View File

@ -11,6 +11,7 @@ import {CommonModule} from '@angular/common';
import {ApplicationRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactoryResolver, ComponentRef, Directive, DoCheck, EmbeddedViewRef, ErrorHandler, Input, NgModule, OnInit, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {BehaviorSubject} from 'rxjs';
describe('change detection', () => {
@ -913,6 +914,41 @@ describe('change detection', () => {
expect(fixture.nativeElement.textContent).toEqual('two - two');
});
it('async pipe should trigger CD for embedded views where the declaration and insertion views are different',
() => {
@Component({
selector: 'insertion',
changeDetection: ChangeDetectionStrategy.OnPush,
template: ` <ng-container [ngTemplateOutlet]="template"> </ng-container> `
})
class Insertion {
@Input() template !: TemplateRef<{}>;
}
// This component uses async pipe (which calls markForCheck) in a view that has different
// insertion and declaration views.
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<insertion [template]="ref"></insertion>
<ng-template #ref>
<span>{{value | async}}</span>
</ng-template>
`
})
class Declaration {
value = new BehaviorSubject('initial value');
}
const fixture = TestBed.configureTestingModule({declarations: [Insertion, Declaration]})
.createComponent(Declaration);
fixture.detectChanges();
expect(fixture.debugElement.nativeElement.textContent).toContain('initial value');
fixture.componentInstance.value.next('new value');
fixture.detectChanges();
expect(fixture.debugElement.nativeElement.textContent).toContain('new value');
});
// TODO(kara): add test for dynamic views once bug fix is in
});