import { TestBed } from '@angular/core/testing' ; import { DOCUMENT } from '@angular/common' ; import { ɵgetDOM as getDOM } from '@angular/platform-browser' ; import { destroyPlatform , createPlatform } from '@angular/core' ; function createRootElement ( ) { const document = TestBed . inject ( DOCUMENT ) ; const root = getDOM ( ) . createElement ( 'app-root' , document ) ; document . body . appendChild ( root ) ; } function removeRootElement ( ) { const root = document . getElementsByTagName ( 'app-root' ) . item ( 0 ) ! ; try { document . body . removeChild ( root ) ; } catch { } } function destroyPlatformBeforeBootstrappingTheNewOne ( ) { destroyPlatform ( ) ; createRootElement ( ) ; } function resetPlatformAfterBootstrapping ( ) { removeRootElement ( ) ; destroyPlatform ( ) ; createPlatform ( TestBed ) ; } export function freshPlatform ( fn ) { return async function testWithAFreshPlatform ( this , ... args ) { try { destroyPlatformBeforeBootstrappingTheNewOne ( ) ; return await fn . apply ( this , args ) ; } finally { resetPlatformAfterBootstrapping ( ) ; } } ; }