@@ -23,7 +23,7 @@ import { createSelectOptions, createType, tab } from './user-events';
23
23
const mountedFixtures = new Set < ComponentFixture < any > > ( ) ;
24
24
25
25
dtlConfigure ( {
26
- eventWrapper : cb => {
26
+ eventWrapper : ( cb ) => {
27
27
const result = cb ( ) ;
28
28
detectChangesForMountedFixtures ( ) ;
29
29
return result ;
@@ -69,7 +69,7 @@ export async function render<SutType, WrapperType = SutType>(
69
69
if ( componentProviders ) {
70
70
componentProviders
71
71
. reduce ( ( acc , provider ) => acc . concat ( provider ) , [ ] )
72
- . forEach ( p => {
72
+ . forEach ( ( p ) => {
73
73
const { provide, ...provider } = p ;
74
74
TestBed . overrideProvider ( provide , provider ) ;
75
75
} ) ;
@@ -103,17 +103,14 @@ export async function render<SutType, WrapperType = SutType>(
103
103
detectChanges ( ) ;
104
104
}
105
105
106
- const eventsWithDetectChanges = Object . keys ( dtlFireEvent ) . reduce (
107
- ( events , key ) => {
108
- events [ key ] = ( element : HTMLElement , options ?: { } ) => {
109
- const result = dtlFireEvent [ key ] ( element , options ) ;
110
- detectChanges ( ) ;
111
- return result ;
112
- } ;
113
- return events ;
114
- } ,
115
- { } as FireFunction & FireObject ,
116
- ) ;
106
+ const eventsWithDetectChanges = Object . keys ( dtlFireEvent ) . reduce ( ( events , key ) => {
107
+ events [ key ] = ( element : HTMLElement , options ?: { } ) => {
108
+ const result = dtlFireEvent [ key ] ( element , options ) ;
109
+ detectChanges ( ) ;
110
+ return result ;
111
+ } ;
112
+ return events ;
113
+ } , { } as FireFunction & FireObject ) ;
117
114
118
115
const rerender = ( rerenderedProperties : Partial < SutType > ) => {
119
116
setComponentProperties ( fixture , { componentProperties : rerenderedProperties } ) ;
@@ -177,7 +174,7 @@ export async function render<SutType, WrapperType = SutType>(
177
174
container : fixture . nativeElement ,
178
175
debug : ( element = fixture . nativeElement , maxLength , options ) =>
179
176
Array . isArray ( element )
180
- ? element . forEach ( e => console . log ( dtlPrettyDOM ( e , maxLength , options ) ) )
177
+ ? element . forEach ( ( e ) => console . log ( dtlPrettyDOM ( e , maxLength , options ) ) )
181
178
: console . log ( dtlPrettyDOM ( element , maxLength , options ) ) ,
182
179
type : createType ( eventsWithDetectChanges ) ,
183
180
selectOptions : createSelectOptions ( eventsWithDetectChanges ) ,
@@ -275,14 +272,14 @@ async function waitForElementToBeRemovedWrapper<T>(
275
272
let cb ;
276
273
if ( typeof callback !== 'function' ) {
277
274
const elements = ( Array . isArray ( callback ) ? callback : [ callback ] ) as HTMLElement [ ] ;
278
- const getRemainingElements = elements . map ( element => {
275
+ const getRemainingElements = elements . map ( ( element ) => {
279
276
let parent = element . parentElement ;
280
277
while ( parent . parentElement ) {
281
278
parent = parent . parentElement ;
282
279
}
283
280
return ( ) => ( parent . contains ( element ) ? element : null ) ;
284
281
} ) ;
285
- cb = ( ) => getRemainingElements . map ( c => c ( ) ) . filter ( Boolean ) ;
282
+ cb = ( ) => getRemainingElements . map ( ( c ) => c ( ) ) . filter ( Boolean ) ;
286
283
} else {
287
284
cb = callback ;
288
285
}
@@ -317,34 +314,31 @@ class WrapperComponent {}
317
314
* Wrap findBy queries to poke the Angular change detection cycle
318
315
*/
319
316
function replaceFindWithFindAndDetectChanges < T > ( container : HTMLElement , originalQueriesForContainer : T ) : T {
320
- return Object . keys ( originalQueriesForContainer ) . reduce (
321
- ( newQueries , key ) => {
322
- if ( key . startsWith ( 'find' ) ) {
323
- const getByQuery = dtlQueries [ key . replace ( 'find' , 'get' ) ] ;
324
- newQueries [ key ] = async ( text , options , waitOptions ) => {
325
- // original implementation at https://github.com/testing-library/dom-testing-library/blob/master/src/query-helpers.js
326
- const result = await waitForWrapper (
327
- detectChangesForMountedFixtures ,
328
- ( ) => getByQuery ( container , text , options ) ,
329
- waitOptions ,
330
- ) ;
331
- return result ;
332
- } ;
333
- } else {
334
- newQueries [ key ] = originalQueriesForContainer [ key ] ;
335
- }
317
+ return Object . keys ( originalQueriesForContainer ) . reduce ( ( newQueries , key ) => {
318
+ if ( key . startsWith ( 'find' ) ) {
319
+ const getByQuery = dtlQueries [ key . replace ( 'find' , 'get' ) ] ;
320
+ newQueries [ key ] = async ( text , options , waitOptions ) => {
321
+ // original implementation at https://github.com/testing-library/dom-testing-library/blob/master/src/query-helpers.js
322
+ const result = await waitForWrapper (
323
+ detectChangesForMountedFixtures ,
324
+ ( ) => getByQuery ( container , text , options ) ,
325
+ waitOptions ,
326
+ ) ;
327
+ return result ;
328
+ } ;
329
+ } else {
330
+ newQueries [ key ] = originalQueriesForContainer [ key ] ;
331
+ }
336
332
337
- return newQueries ;
338
- } ,
339
- { } as T ,
340
- ) ;
333
+ return newQueries ;
334
+ } , { } as T ) ;
341
335
}
342
336
343
337
/**
344
338
* Call detectChanges for all fixtures
345
339
*/
346
340
function detectChangesForMountedFixtures ( ) {
347
- mountedFixtures . forEach ( fixture => {
341
+ mountedFixtures . forEach ( ( fixture ) => {
348
342
try {
349
343
fixture . detectChanges ( ) ;
350
344
} catch ( err ) {
@@ -358,17 +352,14 @@ function detectChangesForMountedFixtures() {
358
352
/**
359
353
* Wrap dom-fireEvent to poke the Angular change detection cycle after an event is fired
360
354
*/
361
- const fireEvent = Object . keys ( dtlFireEvent ) . reduce (
362
- ( events , key ) => {
363
- events [ key ] = ( element : HTMLElement , options ?: { } ) => {
364
- const result = dtlFireEvent [ key ] ( element , options ) ;
365
- detectChangesForMountedFixtures ( ) ;
366
- return result ;
367
- } ;
368
- return events ;
369
- } ,
370
- { } as typeof dtlFireEvent ,
371
- ) ;
355
+ const fireEvent = Object . keys ( dtlFireEvent ) . reduce ( ( events , key ) => {
356
+ events [ key ] = ( element : HTMLElement , options ?: { } ) => {
357
+ const result = dtlFireEvent [ key ] ( element , options ) ;
358
+ detectChangesForMountedFixtures ( ) ;
359
+ return result ;
360
+ } ;
361
+ return events ;
362
+ } , { } as typeof dtlFireEvent ) ;
372
363
373
364
/**
374
365
* Re-export screen with patched queries
0 commit comments