import { Type } from '@angular/core' ; import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ; import { FormsModule , ReactiveFormsModule } from '@angular/forms' ; export function dispatchInputEvent ( inputElement , text ) { inputElement . value = text ; inputElement . dispatchEvent ( new Event ( 'input' ) ) ; } export interface Context < T > { fixture ? : ComponentFixture < T > ; inputElement ? : HTMLInputElement ; } export function setupTemplateDrivenForms < TComp , TAcess > ( context , testComponent , acessor ? ) { beforeEach ( waitForAsync ( ( ) => { TestBed . configureTestingModule ( { declarations : [ testComponent , ... ( acessor ? [ acessor ] : [ ] ) ] , imports : [ FormsModule ] , teardown : { destroyAfterEach : false } } ) . compileComponents ( ) ; } ) ) ; beforeEach ( ( ) => { context . fixture = TestBed . createComponent ( testComponent ) ; } ) ; beforeEach ( waitForAsync ( ( ) => { context . fixture . detectChanges ( ) ; context . fixture . whenStable ( ) ; } ) ) ; beforeEach ( ( ) => context . inputElement = context . fixture . nativeElement . querySelector ( 'input' ) ) ; } export function setupReactiveForms < TComp , TAcess > ( context , testComponent , acessor ? ) { beforeEach ( waitForAsync ( ( ) => { TestBed . configureTestingModule ( { declarations : [ testComponent , ... ( acessor ? [ acessor ] : [ ] ) ] , imports : [ ReactiveFormsModule ] , teardown : { destroyAfterEach : false } } ) . compileComponents ( ) ; } ) ) ; beforeEach ( ( ) => { context . fixture = TestBed . createComponent ( testComponent ) ; context . fixture . detectChanges ( ) ; } ) ; beforeEach ( ( ) => context . inputElement = context . fixture . nativeElement . querySelector ( 'input' ) ) ; }