fix(ivy): provide NgZone to ComponentRef (#26898)
Fixes the r3 `TestBed` not providing an `NgZone` to the `ComponentFixture`. PR Close #26898
This commit is contained in:
parent
9729e8f4b9
commit
e5c9f7a507
|
@ -12,7 +12,7 @@ import {ComponentFixture} from './component_fixture';
|
|||
import {MetadataOverride} from './metadata_override';
|
||||
import {ComponentResolver, DirectiveResolver, NgModuleResolver, PipeResolver, Resolver} from './resolvers';
|
||||
import {TestBed} from './test_bed';
|
||||
import {ComponentFixtureAutoDetect, TestBedStatic, TestComponentRenderer, TestModuleMetadata} from './test_bed_common';
|
||||
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBedStatic, TestComponentRenderer, TestModuleMetadata} from './test_bed_common';
|
||||
|
||||
let _nextRootElementId = 0;
|
||||
|
||||
|
@ -357,11 +357,16 @@ export class TestBedRender3 implements Injector, TestBed {
|
|||
`It looks like '${stringify(type)}' has not been IVY compiled - it has no 'ngComponentDef' field`);
|
||||
}
|
||||
|
||||
const noNgZone: boolean = this.get(ComponentFixtureNoNgZone, false);
|
||||
const autoDetect: boolean = this.get(ComponentFixtureAutoDetect, false);
|
||||
const ngZone: NgZone = noNgZone ? null : this.get(NgZone, null);
|
||||
const componentFactory = new ComponentFactory(componentDef);
|
||||
const initComponent = () => {
|
||||
const componentRef =
|
||||
componentFactory.create(Injector.NULL, [], `#${rootElId}`, this._moduleRef);
|
||||
const autoDetect: boolean = this.get(ComponentFixtureAutoDetect, false);
|
||||
const fixture = new ComponentFixture<any>(componentRef, this.get(NgZone), autoDetect);
|
||||
return new ComponentFixture<any>(componentRef, ngZone, autoDetect);
|
||||
};
|
||||
const fixture = ngZone ? ngZone.run(initComponent) : initComponent();
|
||||
this._activeFixtures.push(fixture);
|
||||
return fixture;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue