Skip to content

Commit 4de4b29

Browse files
authored
test(material/chips): remove dependency on NoopAnimationsModule (#31791)
We had a few tests in the chips that were only passing with `NoopAnimationsModule`. These changes rework the tests and drop the dependency.
1 parent 8704335 commit 4de4b29

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/material/chips/chip-grid.spec.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
3737
import {ComponentFixture, TestBed, fakeAsync, flush, tick} from '@angular/core/testing';
3838
import {FormControl, FormsModule, NgForm, ReactiveFormsModule, Validators} from '@angular/forms';
3939
import {By} from '@angular/platform-browser';
40-
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
4140
import {MATERIAL_ANIMATIONS} from '../core';
4241
import {MatError, MatFormField, MatHint, MatLabel} from '../form-field';
4342
import {
@@ -178,13 +177,14 @@ describe('MatChipGrid', () => {
178177

179178
describe('on chip destroy', () => {
180179
it('should focus the next item', () => {
181-
// TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
182-
// It can indicate a deeper issue with the chips.
183-
const fixture = createComponent(StandardChipGrid, undefined, [NoopAnimationsModule]);
184-
const midItem = chips.get(2)!;
180+
const fixture = createComponent(StandardChipGrid);
181+
const midItemAction = primaryActions[2];
182+
patchElementFocus(midItemAction);
185183

186184
// Focus the middle item
187-
midItem.focus();
185+
midItemAction.focus();
186+
fixture.changeDetectorRef.markForCheck();
187+
fixture.detectChanges();
188188

189189
// Destroy the middle item
190190
testComponent.chips.splice(2, 1);
@@ -196,11 +196,14 @@ describe('MatChipGrid', () => {
196196
});
197197

198198
it('should focus the previous item', () => {
199-
// TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
200-
// It can indicate a deeper issue with the chips.
201-
const fixture = createComponent(StandardChipGrid, undefined, [NoopAnimationsModule]);
199+
const fixture = createComponent(StandardChipGrid);
200+
const lastAction = primaryActions[primaryActions.length - 1];
201+
202202
// Focus the last item
203-
chips.last.focus();
203+
patchElementFocus(lastAction);
204+
lastAction.focus();
205+
fixture.changeDetectorRef.markForCheck();
206+
fixture.detectChanges();
204207

205208
// Destroy the last item
206209
testComponent.chips.pop();
@@ -212,9 +215,7 @@ describe('MatChipGrid', () => {
212215
});
213216

214217
it('should not focus if chip grid is not focused', fakeAsync(() => {
215-
// TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
216-
// It can indicate a deeper issue with the chips.
217-
const fixture = createComponent(StandardChipGrid, undefined, [NoopAnimationsModule]);
218+
const fixture = createComponent(StandardChipGrid);
218219
const midItem = chips.get(2)!;
219220

220221
// Focus and blur the middle item
@@ -233,9 +234,7 @@ describe('MatChipGrid', () => {
233234
}));
234235

235236
it('should focus the grid if the last focused item is removed', () => {
236-
// TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
237-
// It can indicate a deeper issue with the chips.
238-
const fixture = createComponent(StandardChipGrid, undefined, [NoopAnimationsModule]);
237+
const fixture = createComponent(StandardChipGrid);
239238
testComponent.chips = [0];
240239
fixture.changeDetectorRef.markForCheck();
241240

@@ -252,7 +251,7 @@ describe('MatChipGrid', () => {
252251
});
253252

254253
it('should have a focus indicator', () => {
255-
createComponent(StandardChipGrid, undefined, [NoopAnimationsModule]);
254+
createComponent(StandardChipGrid);
256255
const focusIndicators = chipGridNativeElement.querySelectorAll(
257256
'.mat-mdc-chip-primary-focus-indicator',
258257
);
@@ -510,9 +509,7 @@ describe('MatChipGrid', () => {
510509
describe('FormFieldChipGrid', () => {
511510
describe('keyboard behavior', () => {
512511
it('should maintain focus if the active chip is deleted', () => {
513-
// TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
514-
// It can indicate a deeper issue with the chips.
515-
const fixture = createComponent(FormFieldChipGrid, undefined, [NoopAnimationsModule]);
512+
const fixture = createComponent(FormFieldChipGrid);
516513
const secondChip = fixture.nativeElement.querySelectorAll('.mat-mdc-chip')[1];
517514
const secondChipAction = secondChip.querySelector('.mdc-evolution-chip__action--primary');
518515

@@ -658,9 +655,7 @@ describe('MatChipGrid', () => {
658655

659656
describe('with chip remove', () => {
660657
it('should properly focus next item if chip is removed through click', fakeAsync(() => {
661-
// TODO(crisbeto): this test fails without the NoopAnimationsModule for some reason.
662-
// It can indicate a deeper issue with the chips.
663-
const fixture = createComponent(ChipGridWithRemove, undefined, [NoopAnimationsModule]);
658+
const fixture = createComponent(ChipGridWithRemove);
664659
flush();
665660
const trailingActions = chipGridNativeElement.querySelectorAll<HTMLElement>(
666661
'.mdc-evolution-chip__action--secondary',

0 commit comments

Comments
 (0)