@@ -38,6 +38,7 @@ import {MatFormFieldModule} from '../form-field';
3838import { MatInputModule } from '../input' ;
3939import { By } from '@angular/platform-browser' ;
4040import { MatChipEvent , MatChipGrid , MatChipInputEvent , MatChipRow , MatChipsModule } from './index' ;
41+ import { MATERIAL_ANIMATIONS } from '../core' ;
4142import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
4243
4344describe ( 'MatChipGrid' , ( ) => {
@@ -121,27 +122,25 @@ describe('MatChipGrid', () => {
121122 } ) ;
122123
123124 describe ( 'focus behaviors' , ( ) => {
124- let fixture : ComponentFixture < StandardChipGrid > ;
125-
126- beforeEach ( ( ) => {
127- fixture = createComponent ( StandardChipGrid ) ;
128- } ) ;
129-
130125 it ( 'should focus the first chip on focus' , ( ) => {
126+ const fixture = createComponent ( StandardChipGrid ) ;
131127 chipGridInstance . focus ( ) ;
132128 fixture . detectChanges ( ) ;
133129
134130 expect ( document . activeElement ) . toBe ( primaryActions [ 0 ] ) ;
135131 } ) ;
136132
137133 it ( 'should focus the primary action when calling the `focus` method' , ( ) => {
134+ const fixture = createComponent ( StandardChipGrid ) ;
138135 chips . last . focus ( ) ;
139136 fixture . detectChanges ( ) ;
140137
141138 expect ( document . activeElement ) . toBe ( primaryActions [ primaryActions . length - 1 ] ) ;
142139 } ) ;
143140
144141 it ( 'should not be able to become focused when disabled' , ( ) => {
142+ const fixture = createComponent ( StandardChipGrid ) ;
143+
145144 expect ( chipGridInstance . focused )
146145 . withContext ( 'Expected grid to not be focused.' )
147146 . toBe ( false ) ;
@@ -159,6 +158,7 @@ describe('MatChipGrid', () => {
159158 } ) ;
160159
161160 it ( 'should remove the tabindex from the grid if it is disabled' , ( ) => {
161+ const fixture = createComponent ( StandardChipGrid ) ;
162162 expect ( chipGridNativeElement . getAttribute ( 'tabindex' ) ) . toBe ( '0' ) ;
163163
164164 chipGridInstance . disabled = true ;
@@ -170,6 +170,9 @@ describe('MatChipGrid', () => {
170170
171171 describe ( 'on chip destroy' , ( ) => {
172172 it ( 'should focus the next item' , ( ) => {
173+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
174+ // It can indicate a deeper issue with the chips.
175+ const fixture = createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
173176 const midItem = chips . get ( 2 ) ! ;
174177
175178 // Focus the middle item
@@ -185,6 +188,9 @@ describe('MatChipGrid', () => {
185188 } ) ;
186189
187190 it ( 'should focus the previous item' , ( ) => {
191+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
192+ // It can indicate a deeper issue with the chips.
193+ const fixture = createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
188194 // Focus the last item
189195 chips . last . focus ( ) ;
190196
@@ -198,6 +204,9 @@ describe('MatChipGrid', () => {
198204 } ) ;
199205
200206 it ( 'should not focus if chip grid is not focused' , fakeAsync ( ( ) => {
207+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
208+ // It can indicate a deeper issue with the chips.
209+ const fixture = createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
201210 const midItem = chips . get ( 2 ) ! ;
202211
203212 // Focus and blur the middle item
@@ -216,6 +225,9 @@ describe('MatChipGrid', () => {
216225 } ) ) ;
217226
218227 it ( 'should focus the grid if the last focused item is removed' , ( ) => {
228+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
229+ // It can indicate a deeper issue with the chips.
230+ const fixture = createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
219231 testComponent . chips = [ 0 ] ;
220232 fixture . changeDetectorRef . markForCheck ( ) ;
221233
@@ -488,14 +500,11 @@ describe('MatChipGrid', () => {
488500 } ) ;
489501
490502 describe ( 'FormFieldChipGrid' , ( ) => {
491- let fixture : ComponentFixture < FormFieldChipGrid > ;
492-
493- beforeEach ( ( ) => {
494- fixture = createComponent ( FormFieldChipGrid ) ;
495- } ) ;
496-
497503 describe ( 'keyboard behavior' , ( ) => {
498504 it ( 'should maintain focus if the active chip is deleted' , ( ) => {
505+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
506+ // It can indicate a deeper issue with the chips.
507+ const fixture = createComponent ( FormFieldChipGrid , undefined , [ NoopAnimationsModule ] ) ;
499508 const secondChip = fixture . nativeElement . querySelectorAll ( '.mat-mdc-chip' ) [ 1 ] ;
500509 const secondChipAction = secondChip . querySelector ( '.mdc-evolution-chip__action--primary' ) ;
501510
@@ -512,6 +521,7 @@ describe('MatChipGrid', () => {
512521
513522 describe ( 'when the input has focus' , ( ) => {
514523 it ( 'should not focus the last chip when press DELETE' , ( ) => {
524+ const fixture = createComponent ( FormFieldChipGrid ) ;
515525 let nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
516526
517527 // Focus the input
@@ -527,6 +537,7 @@ describe('MatChipGrid', () => {
527537 } ) ;
528538
529539 it ( 'should focus the last chip when press BACKSPACE' , ( ) => {
540+ const fixture = createComponent ( FormFieldChipGrid ) ;
530541 let nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
531542
532543 // Focus the input
@@ -542,6 +553,7 @@ describe('MatChipGrid', () => {
542553 } ) ;
543554
544555 it ( 'should not focus the last chip when pressing BACKSPACE on a non-empty input' , ( ) => {
556+ const fixture = createComponent ( FormFieldChipGrid ) ;
545557 const nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
546558 nativeInput . value = 'hello' ;
547559 nativeInput . focus ( ) ;
@@ -558,6 +570,7 @@ describe('MatChipGrid', () => {
558570 } ) ;
559571
560572 it ( 'should complete the stateChanges stream on destroy' , ( ) => {
573+ const fixture = createComponent ( FormFieldChipGrid ) ;
561574 const spy = jasmine . createSpy ( 'stateChanges complete' ) ;
562575 const subscription = chipGridInstance . stateChanges . subscribe ( { complete : spy } ) ;
563576
@@ -568,18 +581,14 @@ describe('MatChipGrid', () => {
568581 } ) ;
569582
570583 describe ( 'with chip remove' , ( ) => {
571- let fixture : ComponentFixture < ChipGridWithRemove > ;
572- let trailingActions : NodeListOf < HTMLElement > ;
573-
574- beforeEach ( fakeAsync ( ( ) => {
575- fixture = createComponent ( ChipGridWithRemove ) ;
584+ it ( 'should properly focus next item if chip is removed through click' , fakeAsync ( ( ) => {
585+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
586+ // It can indicate a deeper issue with the chips.
587+ const fixture = createComponent ( ChipGridWithRemove , undefined , [ NoopAnimationsModule ] ) ;
576588 flush ( ) ;
577- trailingActions = chipGridNativeElement . querySelectorAll (
589+ const trailingActions = chipGridNativeElement . querySelectorAll < HTMLElement > (
578590 '.mdc-evolution-chip__action--trailing' ,
579591 ) ;
580- } ) ) ;
581-
582- it ( 'should properly focus next item if chip is removed through click' , fakeAsync ( ( ) => {
583592 const chip = chips . get ( 2 ) ! ;
584593 chip . focus ( ) ;
585594 fixture . detectChanges ( ) ;
@@ -1018,6 +1027,7 @@ describe('MatChipGrid', () => {
10181027 function createComponent < T > (
10191028 component : Type < T > ,
10201029 direction : Direction = 'ltr' ,
1030+ additionalImports : Type < unknown > [ ] = [ ] ,
10211031 ) : ComponentFixture < T > {
10221032 directionality = {
10231033 value : direction ,
@@ -1031,9 +1041,12 @@ describe('MatChipGrid', () => {
10311041 MatChipsModule ,
10321042 MatFormFieldModule ,
10331043 MatInputModule ,
1034- NoopAnimationsModule ,
1044+ ...additionalImports ,
1045+ ] ,
1046+ providers : [
1047+ { provide : Directionality , useValue : directionality } ,
1048+ { provide : MATERIAL_ANIMATIONS , useValue : { animationsDisabled : true } } ,
10351049 ] ,
1036- providers : [ { provide : Directionality , useValue : directionality } ] ,
10371050 declarations : [ component ] ,
10381051 } ) ;
10391052
0 commit comments