@@ -351,27 +351,12 @@ class ElementDataSource extends DataSource<PeriodicElement> {
351351}
352352
353353// There's 1px of variance between different browsers in terms of positioning.
354- const approximateMatcher : jasmine . CustomMatcherFactories = {
355- isApproximately : ( ) => ( {
356- compare : ( actual : number , expected : number ) => {
357- const result = {
358- pass : false ,
359- message : `Expected ${ actual } to be within 1 of ${ expected } ` ,
360- } ;
361-
362- result . pass = actual === expected || actual === expected + 1 || actual === expected - 1 ;
363-
364- return result ;
365- } ,
366- } ) ,
367- } ;
368-
369- interface NumberMatchers extends jasmine . Matchers < number > {
370- isApproximately ( expected : number ) : void ;
371- not : NumberMatchers ;
372- }
373- declare global {
374- function expect ( actual : number ) : NumberMatchers ;
354+ function expectApproximate ( actual : number , expected : number , shouldBeApproximate = true ) {
355+ expect ( actual === expected || actual === expected + 1 || actual === expected - 1 )
356+ . withContext (
357+ `Expected ${ actual } ${ shouldBeApproximate ? '' : ' not' } to be within 1 of ${ expected } ` ,
358+ )
359+ . toBe ( shouldBeApproximate ) ;
375360}
376361
377362const testCases = [
@@ -391,7 +376,6 @@ describe('Material Popover Edit', () => {
391376 let fixture : ComponentFixture < BaseTestComponent > ;
392377
393378 beforeEach ( fakeAsync ( ( ) => {
394- jasmine . addMatchers ( approximateMatcher ) ;
395379 fixture = TestBed . createComponent ( componentClass ) ;
396380 component = fixture . componentInstance ;
397381 fixture . detectChanges ( ) ;
@@ -415,8 +399,8 @@ describe('Material Popover Edit', () => {
415399 component . getOverlayThumbElement ( 2 ) . classList . contains ( 'mat-column-resize-overlay-thumb' ) ,
416400 ) . toBe ( true ) ;
417401
418- expect ( component . getOverlayThumbElement ( 0 ) . offsetHeight ) . isApproximately ( headerRowHeight ) ;
419- expect ( component . getOverlayThumbElement ( 2 ) . offsetHeight ) . isApproximately ( headerRowHeight ) ;
402+ expectApproximate ( component . getOverlayThumbElement ( 0 ) . offsetHeight , headerRowHeight ) ;
403+ expectApproximate ( component . getOverlayThumbElement ( 2 ) . offsetHeight , headerRowHeight ) ;
420404
421405 component . beginColumnResizeWithMouse ( 0 ) ;
422406
@@ -427,11 +411,9 @@ describe('Material Popover Edit', () => {
427411 component . getOverlayThumbElement ( 2 ) . classList . contains ( 'mat-column-resize-overlay-thumb' ) ,
428412 ) . toBe ( true ) ;
429413
430- expect ( component . getOverlayThumbElement ( 0 ) . offsetHeight ) . isApproximately ( tableHeight ) ;
431- expect ( component . getOverlayThumbTopElement ( 0 ) . offsetHeight ) . isApproximately (
432- headerRowHeight ,
433- ) ;
434- expect ( component . getOverlayThumbElement ( 2 ) . offsetHeight ) . isApproximately ( headerRowHeight ) ;
414+ expectApproximate ( component . getOverlayThumbElement ( 0 ) . offsetHeight , tableHeight ) ;
415+ expectApproximate ( component . getOverlayThumbTopElement ( 0 ) . offsetHeight , headerRowHeight ) ;
416+ expectApproximate ( component . getOverlayThumbElement ( 2 ) . offsetHeight , headerRowHeight ) ;
435417
436418 component . completeResizeWithMouseInProgress ( 0 ) ;
437419 component . endHoverState ( ) ;
@@ -462,31 +444,31 @@ describe('Material Popover Edit', () => {
462444 let columnPositionDelta = component . getColumnOriginPosition ( 1 ) - initialColumnPosition ;
463445 // let nextColumnPositionDelta =
464446 // component.getColumnOriginPosition(2) - initialNextColumnPosition;
465- expect ( thumbPositionDelta ) . isApproximately ( columnPositionDelta ) ;
447+ expectApproximate ( thumbPositionDelta , columnPositionDelta ) ;
466448 // TODO: This was commented out after switching from the legacy table to the current
467449 // MDC-based table. This failed by being inaccurate by several pixels.
468- // expect (nextColumnPositionDelta).isApproximately( columnPositionDelta);
450+ // expAppexpectApproximateect (nextColumnPositionDelta, columnPositionDelta);
469451
470452 // TODO: This was commented out after switching from the legacy table to the current
471453 // MDC-based table. This failed by being inaccurate by several pixels.
472- // expect (component.getTableWidth()).isApproximately( initialTableWidth + 5);
473- expect ( component . getColumnWidth ( 1 ) ) . isApproximately ( initialColumnWidth + 5 ) ;
454+ // expAppexpectApproximateect (component.getTableWidth(), initialTableWidth + 5);
455+ expectApproximate ( component . getColumnWidth ( 1 ) , initialColumnWidth + 5 ) ;
474456
475457 component . updateResizeWithMouseInProgress ( 1 ) ;
476458 fixture . detectChanges ( ) ;
477459 flush ( ) ;
478460
479461 thumbPositionDelta = component . getOverlayThumbPosition ( 1 ) - initialThumbPosition ;
480462 columnPositionDelta = component . getColumnOriginPosition ( 1 ) - initialColumnPosition ;
481- expect ( thumbPositionDelta ) . isApproximately ( columnPositionDelta ) ;
463+ expectApproximate ( thumbPositionDelta , columnPositionDelta ) ;
482464
483- expect ( component . getTableWidth ( ) ) . isApproximately ( initialTableWidth + 1 ) ;
484- expect ( component . getColumnWidth ( 1 ) ) . isApproximately ( initialColumnWidth + 1 ) ;
465+ expectApproximate ( component . getTableWidth ( ) , initialTableWidth + 1 ) ;
466+ expectApproximate ( component . getColumnWidth ( 1 ) , initialColumnWidth + 1 ) ;
485467
486468 component . completeResizeWithMouseInProgress ( 1 ) ;
487469 flush ( ) ;
488470
489- expect ( component . getColumnWidth ( 1 ) ) . isApproximately ( initialColumnWidth + 1 ) ;
471+ expectApproximate ( component . getColumnWidth ( 1 ) , initialColumnWidth + 1 ) ;
490472
491473 component . endHoverState ( ) ;
492474 fixture . detectChanges ( ) ;
@@ -509,7 +491,7 @@ describe('Material Popover Edit', () => {
509491 flush ( ) ;
510492
511493 let thumbPositionDelta = component . getOverlayThumbPosition ( 1 ) - initialThumbPosition ;
512- expect ( thumbPositionDelta ) . isApproximately ( 5 ) ;
494+ expectApproximate ( thumbPositionDelta , 5 ) ;
513495 expect ( component . getColumnWidth ( 1 ) ) . toBe ( initialColumnWidth ) ;
514496
515497 component . updateResizeWithMouseInProgress ( 1 ) ;
@@ -524,8 +506,8 @@ describe('Material Popover Edit', () => {
524506 component . completeResizeWithMouseInProgress ( 1 ) ;
525507 flush ( ) ;
526508
527- expect ( component . getTableWidth ( ) ) . isApproximately ( initialTableWidth + 1 ) ;
528- expect ( component . getColumnWidth ( 1 ) ) . isApproximately ( initialColumnWidth + 1 ) ;
509+ expectApproximate ( component . getTableWidth ( ) , initialTableWidth + 1 ) ;
510+ expectApproximate ( component . getColumnWidth ( 1 ) , initialColumnWidth + 1 ) ;
529511
530512 component . endHoverState ( ) ;
531513 fixture . detectChanges ( ) ;
@@ -565,18 +547,18 @@ describe('Material Popover Edit', () => {
565547
566548 let thumbPositionDelta = component . getOverlayThumbPosition ( 1 ) - initialThumbPosition ;
567549 let columnPositionDelta = component . getColumnOriginPosition ( 1 ) - initialColumnPosition ;
568- expect ( thumbPositionDelta ) . isApproximately ( columnPositionDelta ) ;
550+ expectApproximate ( thumbPositionDelta , columnPositionDelta ) ;
569551
570- expect ( component . getColumnWidth ( 1 ) ) . isApproximately ( initialColumnWidth + 5 ) ;
552+ expectApproximate ( component . getColumnWidth ( 1 ) , initialColumnWidth + 5 ) ;
571553 // TODO: This was commented out after switching from the legacy table to the current
572554 // MDC-based table. This failed by being inaccurate by several pixels.
573- // expect (component.getTableWidth()).isApproximately( initialTableWidth + 5);
555+ // expAppexpectApproximateect (component.getTableWidth(), initialTableWidth + 5);
574556
575557 dispatchKeyboardEvent ( document , 'keyup' , ESCAPE ) ;
576558 flush ( ) ;
577559
578- expect ( component . getColumnWidth ( 1 ) ) . isApproximately ( initialColumnWidth ) ;
579- expect ( component . getTableWidth ( ) ) . isApproximately ( initialTableWidth ) ;
560+ expectApproximate ( component . getColumnWidth ( 1 ) , initialColumnWidth ) ;
561+ expectApproximate ( component . getTableWidth ( ) , initialTableWidth ) ;
580562
581563 component . endHoverState ( ) ;
582564 fixture . detectChanges ( ) ;
@@ -631,12 +613,12 @@ describe('Material Popover Edit', () => {
631613
632614 it ( 'performs a column resize triggered via ColumnResizeNotifier' , fakeAsync ( ( ) => {
633615 // Pre-verify that we are not updating the size to the initial size.
634- expect ( component . getColumnWidth ( 1 ) ) . not . isApproximately ( 173 ) ;
616+ expectApproximate ( component . getColumnWidth ( 1 ) , 173 , false ) ;
635617
636618 component . columnResize . columnResizeNotifier . resize ( 'name' , 173 ) ;
637619 flush ( ) ;
638620
639- expect ( component . getColumnWidth ( 1 ) ) . isApproximately ( 173 ) ;
621+ expectApproximate ( component . getColumnWidth ( 1 ) , 173 ) ;
640622 } ) ) ;
641623 } ) ;
642624 }
@@ -647,8 +629,6 @@ describe('Material Popover Edit', () => {
647629 let columnSizeStore : FakeColumnSizeStore ;
648630
649631 beforeEach ( fakeAsync ( ( ) => {
650- jasmine . addMatchers ( approximateMatcher ) ;
651-
652632 TestBed . configureTestingModule ( {
653633 providers : [
654634 FakeColumnSizeStore ,
@@ -663,13 +643,13 @@ describe('Material Popover Edit', () => {
663643 } ) ) ;
664644
665645 it ( 'applies the persisted size' , fakeAsync ( ( ) => {
666- expect ( component . getColumnWidth ( 1 ) ) . not . isApproximately ( 300 ) ;
646+ expectApproximate ( component . getColumnWidth ( 1 ) , 300 , false ) ;
667647
668648 columnSizeStore . emitSize ( 'theTable' , 'name' , 300 ) ;
669649
670650 flush ( ) ;
671651
672- expect ( component . getColumnWidth ( 1 ) ) . isApproximately ( 300 ) ;
652+ expectApproximate ( component . getColumnWidth ( 1 ) , 300 ) ;
673653 } ) ) ;
674654
675655 it ( 'persists the user-triggered size update' , fakeAsync ( ( ) => {
@@ -693,7 +673,7 @@ describe('Material Popover Edit', () => {
693673 const { tableId, columnId, sizePx} = columnSizeStore . setSizeCalls [ 0 ] ;
694674 expect ( tableId ) . toBe ( 'theTable' ) ;
695675 expect ( columnId ) . toBe ( 'name' ) ;
696- expect ( sizePx ) . isApproximately ( initialColumnWidth + 5 ) ;
676+ expectApproximate ( sizePx , initialColumnWidth + 5 ) ;
697677 } ) ) ;
698678
699679 it ( 'persists the user-triggered size update (live updates off)' , fakeAsync ( ( ) => {
@@ -719,7 +699,7 @@ describe('Material Popover Edit', () => {
719699 const { tableId, columnId, sizePx} = columnSizeStore . setSizeCalls [ 0 ] ;
720700 expect ( tableId ) . toBe ( 'theTable' ) ;
721701 expect ( columnId ) . toBe ( 'name' ) ;
722- expect ( sizePx ) . isApproximately ( initialColumnWidth + 5 ) ;
702+ expectApproximate ( sizePx , initialColumnWidth + 5 ) ;
723703 } ) ) ;
724704 } ) ;
725705} ) ;
0 commit comments