@@ -12,7 +12,7 @@ import {ComponentFixture} from './component_fixture';
1212import { MetadataOverride } from './metadata_override' ;
1313import { ComponentResolver , DirectiveResolver , NgModuleResolver , PipeResolver , Resolver } from './resolvers' ;
1414import { TestBed } from './test_bed' ;
15- import { ComponentFixtureAutoDetect , TestBedStatic , TestComponentRenderer , TestModuleMetadata } from './test_bed_common' ;
15+ import { ComponentFixtureAutoDetect , ComponentFixtureNoNgZone , TestBedStatic , TestComponentRenderer , TestModuleMetadata } from './test_bed_common' ;
1616
1717let _nextRootElementId = 0 ;
1818
@@ -357,11 +357,16 @@ export class TestBedRender3 implements Injector, TestBed {
357357 `It looks like '${ stringify ( type ) } ' has not been IVY compiled - it has no 'ngComponentDef' field` ) ;
358358 }
359359
360- const componentFactory = new ComponentFactory ( componentDef ) ;
361- const componentRef =
362- componentFactory . create ( Injector . NULL , [ ] , `#${ rootElId } ` , this . _moduleRef ) ;
360+ const noNgZone : boolean = this . get ( ComponentFixtureNoNgZone , false ) ;
363361 const autoDetect : boolean = this . get ( ComponentFixtureAutoDetect , false ) ;
364- const fixture = new ComponentFixture < any > ( componentRef , this . get ( NgZone ) , autoDetect ) ;
362+ const ngZone : NgZone = noNgZone ? null : this . get ( NgZone , null ) ;
363+ const componentFactory = new ComponentFactory ( componentDef ) ;
364+ const initComponent = ( ) => {
365+ const componentRef =
366+ componentFactory . create ( Injector . NULL , [ ] , `#${ rootElId } ` , this . _moduleRef ) ;
367+ return new ComponentFixture < any > ( componentRef , ngZone , autoDetect ) ;
368+ } ;
369+ const fixture = ngZone ? ngZone . run ( initComponent ) : initComponent ( ) ;
365370 this . _activeFixtures . push ( fixture ) ;
366371 return fixture ;
367372 }
0 commit comments