@@ -20,6 +20,8 @@ import { createSelectOptions, createType, tab } from './user-events';
2020@Component ( { selector : 'wrapper-component' , template : '' } )
2121class WrapperComponent { }
2222
23+ const mountedContainers = new Set ( ) ;
24+
2325export async function render < ComponentType > (
2426 component : Type < ComponentType > ,
2527 renderOptions ?: RenderComponentOptions < ComponentType > ,
@@ -77,6 +79,7 @@ export async function render<SutType, WrapperType = SutType>(
7779 }
7880
7981 await TestBed . compileComponents ( ) ;
82+ mountedContainers . add ( fixture . nativeElement ) ;
8083
8184 let isAlive = true ;
8285 fixture . componentRef . onDestroy ( ( ) => ( isAlive = false ) ) ;
@@ -236,3 +239,20 @@ function addAutoImports({ imports, routes }: Pick<RenderComponentOptions<any>, '
236239
237240 return [ ...imports , ...animations ( ) , ...routing ( ) ] ;
238241}
242+
243+ function cleanup ( ) {
244+ mountedContainers . forEach ( cleanupAtContainer ) ;
245+ }
246+
247+ function cleanupAtContainer ( container ) {
248+ if ( container . parentNode === document . body ) {
249+ document . body . removeChild ( container ) ;
250+ }
251+ mountedContainers . delete ( container ) ;
252+ }
253+
254+ if ( typeof afterEach === 'function' && ! process . env . ATL_SKIP_AUTO_CLEANUP ) {
255+ afterEach ( async ( ) => {
256+ cleanup ( ) ;
257+ } ) ;
258+ }
0 commit comments