test(ivy): non-regression test for ViewContainerRef queried on ng-container (#33939)

Closes #31971

PR Close #33939
This commit is contained in:
Pawel Kozlowski 2019-11-20 18:03:51 +01:00 committed by Alex Rickabaugh
parent 27562e92db
commit 51cee50ee3
1 changed files with 72 additions and 22 deletions

View File

@ -543,8 +543,58 @@ describe('view insertion', () => {
describe('non-regression', () => { describe('non-regression', () => {
// https://github.com/angular/angular/issues/31971
it('should insert component views into ViewContainerRef injected by querying <ng-container>',
() => {
@Component({selector: 'dynamic-cmpt', template: 'dynamic'})
class DynamicComponent {
}
@Component({
selector: 'app-root',
template: `
<div>start|</div>
<ng-container #container></ng-container>
<div>|end</div>
<div (click)="click()" >|click</div>
`
})
class AppComponent {
@ViewChild('container', {read: ViewContainerRef, static: true})
vcr !: ViewContainerRef;
constructor(private _cfr: ComponentFactoryResolver) {}
click() {
this.vcr.createComponent(this._cfr.resolveComponentFactory(DynamicComponent));
}
}
@NgModule({
declarations: [DynamicComponent],
entryComponents: [DynamicComponent],
})
class TestModule {
}
TestBed.configureTestingModule({
declarations: [AppComponent],
imports: [TestModule],
});
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('start||end|click');
fixture.componentInstance.click();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('start|dynamic|end|click');
});
// https://github.com/angular/angular/issues/33679 // https://github.com/angular/angular/issues/33679
it('should insert views into ViewContainerRef injected by querying <ng-container>', () => { it('should insert embedded views into ViewContainerRef injected by querying <ng-container>',
() => {
@Component({ @Component({
selector: 'app-root', selector: 'app-root',