@@ -2,14 +2,14 @@ import {
22 ApplicationInitStatus ,
33 ChangeDetectorRef ,
44 Component ,
5- isStandalone ,
65 NgZone ,
76 OnChanges ,
87 OutputRef ,
98 OutputRefSubscription ,
109 SimpleChange ,
1110 SimpleChanges ,
1211 Type ,
12+ isStandalone ,
1313} from '@angular/core' ;
1414import { ComponentFixture , DeferBlockBehavior , DeferBlockState , TestBed , tick } from '@angular/core/testing' ;
1515import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -27,14 +27,14 @@ import {
2727 waitForOptions as dtlWaitForOptions ,
2828 within as dtlWithin ,
2929} from '@testing-library/dom' ;
30+ import { getConfig } from './config' ;
3031import {
3132 ComponentOverride ,
33+ OutputRefKeysWithCallback ,
3234 RenderComponentOptions ,
3335 RenderResult ,
3436 RenderTemplateOptions ,
35- OutputRefKeysWithCallback ,
3637} from './models' ;
37- import { getConfig } from './config' ;
3838
3939type SubscribedOutput < T > = readonly [ key : keyof T , callback : ( v : any ) => void , subscription : OutputRefSubscription ] ;
4040
@@ -71,7 +71,7 @@ export async function render<SutType, WrapperType = SutType>(
7171 on = { } ,
7272 componentProviders = [ ] ,
7373 childComponentOverrides = [ ] ,
74- componentImports : componentImports ,
74+ componentImports,
7575 excludeComponentDeclaration = false ,
7676 routes = [ ] ,
7777 removeAngularAttributes = false ,
@@ -116,12 +116,9 @@ export async function render<SutType, WrapperType = SutType>(
116116
117117 await TestBed . compileComponents ( ) ;
118118
119- componentProviders
120- . reduce ( ( acc , provider ) => acc . concat ( provider ) , [ ] as any [ ] )
121- . forEach ( ( p : any ) => {
122- const { provide, ...provider } = p ;
123- TestBed . overrideProvider ( provide , provider ) ;
124- } ) ;
119+ for ( const { provide, ...provider } of componentProviders ) {
120+ TestBed . overrideProvider ( provide , provider ) ;
121+ }
125122
126123 const componentContainer = createComponentFixture ( sut , wrapper ) ;
127124
@@ -158,7 +155,9 @@ export async function render<SutType, WrapperType = SutType>(
158155 let result ;
159156
160157 if ( zone ) {
161- await zone . run ( ( ) => ( result = doNavigate ( ) ) ) ;
158+ await zone . run ( ( ) => {
159+ result = doNavigate ( ) ;
160+ } ) ;
162161 } else {
163162 result = doNavigate ( ) ;
164163 }
@@ -199,15 +198,17 @@ export async function render<SutType, WrapperType = SutType>(
199198 if ( removeAngularAttributes ) {
200199 createdFixture . nativeElement . removeAttribute ( 'ng-version' ) ;
201200 const idAttribute = createdFixture . nativeElement . getAttribute ( 'id' ) ;
202- if ( idAttribute && idAttribute . startsWith ( 'root' ) ) {
201+ if ( idAttribute ? .startsWith ( 'root' ) ) {
203202 createdFixture . nativeElement . removeAttribute ( 'id' ) ;
204203 }
205204 }
206205
207206 mountedFixtures . add ( createdFixture ) ;
208207
209208 let isAlive = true ;
210- createdFixture . componentRef . onDestroy ( ( ) => ( isAlive = false ) ) ;
209+ createdFixture . componentRef . onDestroy ( ( ) => {
210+ isAlive = false ;
211+ } ) ;
211212
212213 if ( hasOnChangesHook ( createdFixture . componentInstance ) && Object . keys ( properties ) . length > 0 ) {
213214 const changes = getChangesObj ( null , componentProperties ) ;
@@ -318,10 +319,15 @@ export async function render<SutType, WrapperType = SutType>(
318319 } ,
319320 debugElement : fixture . debugElement ,
320321 container : fixture . nativeElement ,
321- debug : ( element = fixture . nativeElement , maxLength , options ) =>
322- Array . isArray ( element )
323- ? element . forEach ( ( e ) => console . log ( dtlPrettyDOM ( e , maxLength , options ) ) )
324- : console . log ( dtlPrettyDOM ( element , maxLength , options ) ) ,
322+ debug : ( element = fixture . nativeElement , maxLength , options ) => {
323+ if ( Array . isArray ( element ) ) {
324+ for ( const e of element ) {
325+ console . log ( dtlPrettyDOM ( e , maxLength , options ) ) ;
326+ }
327+ } else {
328+ console . log ( dtlPrettyDOM ( element , maxLength , options ) ) ;
329+ }
330+ } ,
325331 ...replaceFindWithFindAndDetectChanges ( dtlGetQueriesForElement ( fixture . nativeElement , queries ) ) ,
326332 } ;
327333}
@@ -423,9 +429,11 @@ function overrideComponentImports<SutType>(sut: Type<SutType> | string, imports:
423429}
424430
425431function overrideChildComponentProviders ( componentOverrides : ComponentOverride < any > [ ] ) {
426- componentOverrides ?. forEach ( ( { component, providers } ) => {
427- TestBed . overrideComponent ( component , { set : { providers } } ) ;
428- } ) ;
432+ if ( componentOverrides ) {
433+ for ( const { component, providers } of componentOverrides ) {
434+ TestBed . overrideComponent ( component , { set : { providers } } ) ;
435+ }
436+ }
429437}
430438
431439function hasOnChangesHook < SutType > ( componentInstance : SutType ) : componentInstance is SutType & OnChanges {
@@ -439,13 +447,10 @@ function hasOnChangesHook<SutType>(componentInstance: SutType): componentInstanc
439447
440448function getChangesObj ( oldProps : Record < string , any > | null , newProps : Record < string , any > ) {
441449 const isFirstChange = oldProps === null ;
442- return Object . keys ( newProps ) . reduce < SimpleChanges > (
443- ( changes , key ) => ( {
444- ...changes ,
445- [ key ] : new SimpleChange ( isFirstChange ? null : oldProps [ key ] , newProps [ key ] , isFirstChange ) ,
446- } ) ,
447- { } as Record < string , any > ,
448- ) ;
450+ return Object . keys ( newProps ) . reduce < SimpleChanges > ( ( changes , key ) => {
451+ changes [ key ] = new SimpleChange ( isFirstChange ? null : oldProps [ key ] , newProps [ key ] , isFirstChange ) ;
452+ return changes ;
453+ } , { } as Record < string , any > ) ;
449454}
450455
451456function update < SutType > (
@@ -461,10 +466,12 @@ function update<SutType>(
461466 const componentInstance = fixture . componentInstance as Record < string , any > ;
462467 const simpleChanges : SimpleChanges = { } ;
463468
464- for ( const key of prevRenderedKeys ) {
465- if ( ! partialUpdate && ! Object . prototype . hasOwnProperty . call ( newValues , key ) ) {
466- simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , undefined , false ) ;
467- delete componentInstance [ key ] ;
469+ if ( ! partialUpdate ) {
470+ for ( const key of prevRenderedKeys ) {
471+ if ( ! Object . prototype . hasOwnProperty . call ( newValues , key ) ) {
472+ simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , undefined , false ) ;
473+ delete componentInstance [ key ] ;
474+ }
468475 }
469476 }
470477
@@ -643,15 +650,15 @@ function replaceFindWithFindAndDetectChanges<T extends Record<string, any>>(orig
643650 * Call detectChanges for all fixtures
644651 */
645652function detectChangesForMountedFixtures ( ) {
646- mountedFixtures . forEach ( ( fixture ) => {
653+ for ( const fixture of mountedFixtures ) {
647654 try {
648655 fixture . detectChanges ( ) ;
649656 } catch ( err : any ) {
650657 if ( ! err . message . startsWith ( 'ViewDestroyedError' ) ) {
651658 throw err ;
652659 }
653660 }
654- } ) ;
661+ }
655662}
656663
657664/**
0 commit comments