@@ -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
@@ -232,6 +244,7 @@ describe('MatChipGrid', () => {
232244 } ) ;
233245
234246 it ( 'should have a focus indicator' , ( ) => {
247+ createComponent ( StandardChipGrid , undefined , [ NoopAnimationsModule ] ) ;
235248 const focusIndicators = chipGridNativeElement . querySelectorAll (
236249 '.mat-mdc-chip-primary-focus-indicator' ,
237250 ) ;
@@ -488,14 +501,11 @@ describe('MatChipGrid', () => {
488501 } ) ;
489502
490503 describe ( 'FormFieldChipGrid' , ( ) => {
491- let fixture : ComponentFixture < FormFieldChipGrid > ;
492-
493- beforeEach ( ( ) => {
494- fixture = createComponent ( FormFieldChipGrid ) ;
495- } ) ;
496-
497504 describe ( 'keyboard behavior' , ( ) => {
498505 it ( 'should maintain focus if the active chip is deleted' , ( ) => {
506+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
507+ // It can indicate a deeper issue with the chips.
508+ const fixture = createComponent ( FormFieldChipGrid , undefined , [ NoopAnimationsModule ] ) ;
499509 const secondChip = fixture . nativeElement . querySelectorAll ( '.mat-mdc-chip' ) [ 1 ] ;
500510 const secondChipAction = secondChip . querySelector ( '.mdc-evolution-chip__action--primary' ) ;
501511
@@ -512,6 +522,7 @@ describe('MatChipGrid', () => {
512522
513523 describe ( 'when the input has focus' , ( ) => {
514524 it ( 'should not focus the last chip when press DELETE' , ( ) => {
525+ const fixture = createComponent ( FormFieldChipGrid ) ;
515526 let nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
516527
517528 // Focus the input
@@ -527,6 +538,7 @@ describe('MatChipGrid', () => {
527538 } ) ;
528539
529540 it ( 'should focus the last chip when press BACKSPACE' , ( ) => {
541+ const fixture = createComponent ( FormFieldChipGrid ) ;
530542 let nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
531543
532544 // Focus the input
@@ -542,6 +554,7 @@ describe('MatChipGrid', () => {
542554 } ) ;
543555
544556 it ( 'should not focus the last chip when pressing BACKSPACE on a non-empty input' , ( ) => {
557+ const fixture = createComponent ( FormFieldChipGrid ) ;
545558 const nativeInput = fixture . nativeElement . querySelector ( 'input' ) ;
546559 nativeInput . value = 'hello' ;
547560 nativeInput . focus ( ) ;
@@ -558,6 +571,7 @@ describe('MatChipGrid', () => {
558571 } ) ;
559572
560573 it ( 'should complete the stateChanges stream on destroy' , ( ) => {
574+ const fixture = createComponent ( FormFieldChipGrid ) ;
561575 const spy = jasmine . createSpy ( 'stateChanges complete' ) ;
562576 const subscription = chipGridInstance . stateChanges . subscribe ( { complete : spy } ) ;
563577
@@ -568,18 +582,14 @@ describe('MatChipGrid', () => {
568582 } ) ;
569583
570584 describe ( 'with chip remove' , ( ) => {
571- let fixture : ComponentFixture < ChipGridWithRemove > ;
572- let trailingActions : NodeListOf < HTMLElement > ;
573-
574- beforeEach ( fakeAsync ( ( ) => {
575- fixture = createComponent ( ChipGridWithRemove ) ;
585+ it ( 'should properly focus next item if chip is removed through click' , fakeAsync ( ( ) => {
586+ // TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
587+ // It can indicate a deeper issue with the chips.
588+ const fixture = createComponent ( ChipGridWithRemove , undefined , [ NoopAnimationsModule ] ) ;
576589 flush ( ) ;
577- trailingActions = chipGridNativeElement . querySelectorAll (
590+ const trailingActions = chipGridNativeElement . querySelectorAll < HTMLElement > (
578591 '.mdc-evolution-chip__action--trailing' ,
579592 ) ;
580- } ) ) ;
581-
582- it ( 'should properly focus next item if chip is removed through click' , fakeAsync ( ( ) => {
583593 const chip = chips . get ( 2 ) ! ;
584594 chip . focus ( ) ;
585595 fixture . detectChanges ( ) ;
@@ -1018,6 +1028,7 @@ describe('MatChipGrid', () => {
10181028 function createComponent < T > (
10191029 component : Type < T > ,
10201030 direction : Direction = 'ltr' ,
1031+ additionalImports : Type < unknown > [ ] = [ ] ,
10211032 ) : ComponentFixture < T > {
10221033 directionality = {
10231034 value : direction ,
@@ -1031,9 +1042,12 @@ describe('MatChipGrid', () => {
10311042 MatChipsModule ,
10321043 MatFormFieldModule ,
10331044 MatInputModule ,
1034- NoopAnimationsModule ,
1045+ ...additionalImports ,
1046+ ] ,
1047+ providers : [
1048+ { provide : Directionality , useValue : directionality } ,
1049+ { provide : MATERIAL_ANIMATIONS , useValue : { animationsDisabled : true } } ,
10351050 ] ,
1036- providers : [ { provide : Directionality , useValue : directionality } ] ,
10371051 declarations : [ component ] ,
10381052 } ) ;
10391053
0 commit comments