@@ -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,15 +27,16 @@ 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 ,
3537 OutputRefKeysWithCallback ,
3638 Config ,
3739} from './models' ;
38- import { getConfig } from './config' ;
3940
4041type SubscribedOutput < T > = readonly [ key : keyof T , callback : ( v : any ) => void , subscription : OutputRefSubscription ] ;
4142
@@ -72,7 +73,7 @@ export async function render<SutType, WrapperType = SutType>(
7273 on = { } ,
7374 componentProviders = [ ] ,
7475 childComponentOverrides = [ ] ,
75- componentImports : componentImports ,
76+ componentImports,
7677 excludeComponentDeclaration = false ,
7778 routes = [ ] ,
7879 removeAngularAttributes = false ,
@@ -119,12 +120,9 @@ export async function render<SutType, WrapperType = SutType>(
119120
120121 await TestBed . compileComponents ( ) ;
121122
122- componentProviders
123- . reduce ( ( acc , provider ) => acc . concat ( provider ) , [ ] as any [ ] )
124- . forEach ( ( p : any ) => {
125- const { provide, ...provider } = p ;
126- TestBed . overrideProvider ( provide , provider ) ;
127- } ) ;
123+ for ( const { provide, ...provider } of componentProviders ) {
124+ TestBed . overrideProvider ( provide , provider ) ;
125+ }
128126
129127 const componentContainer = createComponentFixture ( sut , wrapper ) ;
130128
@@ -161,7 +159,9 @@ export async function render<SutType, WrapperType = SutType>(
161159 let result ;
162160
163161 if ( zone ) {
164- await zone . run ( ( ) => ( result = doNavigate ( ) ) ) ;
162+ await zone . run ( ( ) => {
163+ result = doNavigate ( ) ;
164+ } ) ;
165165 } else {
166166 result = doNavigate ( ) ;
167167 }
@@ -202,15 +202,17 @@ export async function render<SutType, WrapperType = SutType>(
202202 if ( removeAngularAttributes ) {
203203 createdFixture . nativeElement . removeAttribute ( 'ng-version' ) ;
204204 const idAttribute = createdFixture . nativeElement . getAttribute ( 'id' ) ;
205- if ( idAttribute && idAttribute . startsWith ( 'root' ) ) {
205+ if ( idAttribute ? .startsWith ( 'root' ) ) {
206206 createdFixture . nativeElement . removeAttribute ( 'id' ) ;
207207 }
208208 }
209209
210210 mountedFixtures . add ( createdFixture ) ;
211211
212212 let isAlive = true ;
213- createdFixture . componentRef . onDestroy ( ( ) => ( isAlive = false ) ) ;
213+ createdFixture . componentRef . onDestroy ( ( ) => {
214+ isAlive = false ;
215+ } ) ;
214216
215217 if ( hasOnChangesHook ( createdFixture . componentInstance ) && Object . keys ( properties ) . length > 0 ) {
216218 const changes = getChangesObj ( null , componentProperties ) ;
@@ -321,10 +323,15 @@ export async function render<SutType, WrapperType = SutType>(
321323 } ,
322324 debugElement : fixture . debugElement ,
323325 container : fixture . nativeElement ,
324- debug : ( element = fixture . nativeElement , maxLength , options ) =>
325- Array . isArray ( element )
326- ? element . forEach ( ( e ) => console . log ( dtlPrettyDOM ( e , maxLength , options ) ) )
327- : console . log ( dtlPrettyDOM ( element , maxLength , options ) ) ,
326+ debug : ( element = fixture . nativeElement , maxLength , options ) => {
327+ if ( Array . isArray ( element ) ) {
328+ for ( const e of element ) {
329+ console . log ( dtlPrettyDOM ( e , maxLength , options ) ) ;
330+ }
331+ } else {
332+ console . log ( dtlPrettyDOM ( element , maxLength , options ) ) ;
333+ }
334+ } ,
328335 ...replaceFindWithFindAndDetectChanges ( dtlGetQueriesForElement ( fixture . nativeElement , queries ) ) ,
329336 } ;
330337}
@@ -426,9 +433,11 @@ function overrideComponentImports<SutType>(sut: Type<SutType> | string, imports:
426433}
427434
428435function overrideChildComponentProviders ( componentOverrides : ComponentOverride < any > [ ] ) {
429- componentOverrides ?. forEach ( ( { component, providers } ) => {
430- TestBed . overrideComponent ( component , { set : { providers } } ) ;
431- } ) ;
436+ if ( componentOverrides ) {
437+ for ( const { component, providers } of componentOverrides ) {
438+ TestBed . overrideComponent ( component , { set : { providers } } ) ;
439+ }
440+ }
432441}
433442
434443function hasOnChangesHook < SutType > ( componentInstance : SutType ) : componentInstance is SutType & OnChanges {
@@ -442,13 +451,10 @@ function hasOnChangesHook<SutType>(componentInstance: SutType): componentInstanc
442451
443452function getChangesObj ( oldProps : Record < string , any > | null , newProps : Record < string , any > ) {
444453 const isFirstChange = oldProps === null ;
445- return Object . keys ( newProps ) . reduce < SimpleChanges > (
446- ( changes , key ) => ( {
447- ...changes ,
448- [ key ] : new SimpleChange ( isFirstChange ? null : oldProps [ key ] , newProps [ key ] , isFirstChange ) ,
449- } ) ,
450- { } as Record < string , any > ,
451- ) ;
454+ return Object . keys ( newProps ) . reduce < SimpleChanges > ( ( changes , key ) => {
455+ changes [ key ] = new SimpleChange ( isFirstChange ? null : oldProps [ key ] , newProps [ key ] , isFirstChange ) ;
456+ return changes ;
457+ } , { } as Record < string , any > ) ;
452458}
453459
454460function update < SutType > (
@@ -464,10 +470,12 @@ function update<SutType>(
464470 const componentInstance = fixture . componentInstance as Record < string , any > ;
465471 const simpleChanges : SimpleChanges = { } ;
466472
467- for ( const key of prevRenderedKeys ) {
468- if ( ! partialUpdate && ! Object . prototype . hasOwnProperty . call ( newValues , key ) ) {
469- simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , undefined , false ) ;
470- delete componentInstance [ key ] ;
473+ if ( ! partialUpdate ) {
474+ for ( const key of prevRenderedKeys ) {
475+ if ( ! Object . prototype . hasOwnProperty . call ( newValues , key ) ) {
476+ simpleChanges [ key ] = new SimpleChange ( componentInstance [ key ] , undefined , false ) ;
477+ delete componentInstance [ key ] ;
478+ }
471479 }
472480 }
473481
@@ -647,15 +655,15 @@ function replaceFindWithFindAndDetectChanges<T extends Record<string, any>>(orig
647655 * Call detectChanges for all fixtures
648656 */
649657function detectChangesForMountedFixtures ( ) {
650- mountedFixtures . forEach ( ( fixture ) => {
658+ for ( const fixture of mountedFixtures ) {
651659 try {
652660 fixture . detectChanges ( ) ;
653661 } catch ( err : any ) {
654662 if ( ! err . message . startsWith ( 'ViewDestroyedError' ) ) {
655663 throw err ;
656664 }
657665 }
658- } ) ;
666+ }
659667}
660668
661669/**
0 commit comments