fix(ivy): allow TestBed.createComponent to create components in isolation (#29981)

Prior to this change, components created via TestBed.createComponent in the same test were placed into the same root context, which caused problems in conjunction with fixture.autoDetectChanges usage in the same test. Specifically, change detection was triggered immediately for created component (starting from the 2nd one) even if it was not required/desired. This commit makes Ivy and VE behavior consistent: now every component created via TestBed.createComponent is isolated from each other. Current solution uses host element id naming convention, which is not ideal, but helps avoid public API surface changes at this point (we might revisit this approach later).

Note: this commit also adds extra tests to verify bootstrap and change detection behavior in case of multiple components in `bootstrap` array in @NgModule, to make sure this behavior is aligned between Ivy and VE.

PR Close #29981
This commit is contained in:
Andrew Kushnir
2019-04-18 17:52:04 -07:00
committed by Ben Lesh
parent c1d5fbd0ad
commit f9bb53a761
4 changed files with 126 additions and 4 deletions

View File

@ -343,7 +343,7 @@ export class TestBedRender3 implements Injector, TestBed {
createComponent<T>(type: Type<T>): ComponentFixture<T> {
const testComponentRenderer: TestComponentRenderer = this.get(TestComponentRenderer);
const rootElId = `root${_nextRootElementId++}`;
const rootElId = `root-ng-internal-isolated-${_nextRootElementId++}`;
testComponentRenderer.insertRootElement(rootElId);
const componentDef = (type as any).ngComponentDef;