4
4
waitForAsync ,
5
5
ComponentFixture ,
6
6
fakeAsync ,
7
+ flush ,
7
8
flushMicrotasks ,
8
9
TestBed ,
9
10
tick ,
@@ -203,6 +204,7 @@ describe('MatTable', () => {
203
204
const fixture = TestBed . createComponent ( StickyTableApp ) ;
204
205
fixture . detectChanges ( ) ;
205
206
flushMicrotasks ( ) ;
207
+ flush ( ) ;
206
208
207
209
const stuckCellElement = fixture . nativeElement . querySelector ( '.mat-table th' ) ! ;
208
210
expect ( stuckCellElement . classList ) . toContain ( 'mat-table-sticky' ) ;
@@ -227,6 +229,7 @@ describe('MatTable', () => {
227
229
beforeEach ( fakeAsync ( ( ) => {
228
230
fixture = TestBed . createComponent ( ArrayDataSourceMatTableApp ) ;
229
231
fixture . detectChanges ( ) ;
232
+ flush ( ) ;
230
233
231
234
tableElement = fixture . nativeElement . querySelector ( '.mat-table' ) ;
232
235
component = fixture . componentInstance ;
@@ -300,13 +303,15 @@ describe('MatTable', () => {
300
303
// Change filter to a_1, should match one row
301
304
dataSource . filter = 'a_1' ;
302
305
fixture . detectChanges ( ) ;
306
+ flush ( ) ;
303
307
expect ( dataSource . filteredData . length ) . toBe ( 1 ) ;
304
308
expect ( dataSource . filteredData [ 0 ] ) . toBe ( dataSource . data [ 0 ] ) ;
305
309
expectTableToMatchContent ( tableElement , [
306
310
[ 'Column A' , 'Column B' , 'Column C' ] ,
307
311
[ 'a_1' , 'b_1' , 'c_1' ] ,
308
312
[ 'Footer A' , 'Footer B' , 'Footer C' ] ,
309
313
] ) ;
314
+ flush ( ) ;
310
315
311
316
flushMicrotasks ( ) ; // Resolve promise that updates paginator's length
312
317
expect ( dataSource . paginator ! . length ) . toBe ( 1 ) ;
@@ -321,6 +326,7 @@ describe('MatTable', () => {
321
326
[ 'a_2' , 'b_2' , 'c_2' ] ,
322
327
[ 'Footer A' , 'Footer B' , 'Footer C' ] ,
323
328
] ) ;
329
+ flush ( ) ;
324
330
325
331
// Change filter to empty string, should match all rows
326
332
dataSource . filter = '' ;
@@ -336,6 +342,7 @@ describe('MatTable', () => {
336
342
[ 'a_3' , 'b_3' , 'c_3' ] ,
337
343
[ 'Footer A' , 'Footer B' , 'Footer C' ] ,
338
344
] ) ;
345
+ flush ( ) ;
339
346
340
347
// Change filter function and filter, should match to rows with zebra.
341
348
dataSource . filterPredicate = ( data , filter ) => {
@@ -363,6 +370,7 @@ describe('MatTable', () => {
363
370
[ 'a_2' , 'b_2' , 'c_2' ] ,
364
371
[ 'Footer A' , 'Footer B' , 'Footer C' ] ,
365
372
] ) ;
373
+ flush ( ) ;
366
374
367
375
// Change the filter to a falsy value that might come in from the view.
368
376
dataSource . filter = 0 as any ;
@@ -371,13 +379,15 @@ describe('MatTable', () => {
371
379
[ 'Column A' , 'Column B' , 'Column C' ] ,
372
380
[ 'Footer A' , 'Footer B' , 'Footer C' ] ,
373
381
] ) ;
382
+ flush ( ) ;
374
383
} ) ) ;
375
384
376
385
it ( 'should not match concatenated words' , fakeAsync ( ( ) => {
377
386
// Set the value to the last character of the first
378
387
// column plus the first character of the second column.
379
388
dataSource . filter = '1b' ;
380
389
fixture . detectChanges ( ) ;
390
+ flush ( ) ;
381
391
expect ( dataSource . filteredData . length ) . toBe ( 0 ) ;
382
392
expectTableToMatchContent ( tableElement , [
383
393
[ 'Column A' , 'Column B' , 'Column C' ] ,
@@ -523,6 +533,7 @@ describe('MatTable', () => {
523
533
}
524
534
fixture . detectChanges ( ) ;
525
535
flushMicrotasks ( ) ; // Resolve promise that updates paginator's length
536
+ flush ( ) ;
526
537
expectTableToMatchContent ( tableElement , [
527
538
[ 'Column A' , 'Column B' , 'Column C' ] ,
528
539
[ 'a_1' , 'b_1' , 'c_1' ] ,
@@ -536,6 +547,7 @@ describe('MatTable', () => {
536
547
// Navigate to the next page
537
548
component . paginator . nextPage ( ) ;
538
549
fixture . detectChanges ( ) ;
550
+ flush ( ) ;
539
551
expectTableToMatchContent ( tableElement , [
540
552
[ 'Column A' , 'Column B' , 'Column C' ] ,
541
553
[ 'a_6' , 'b_6' , 'c_6' ] ,
0 commit comments