Skip to content

Commit cff7f5e

Browse files
committed
test(multiple): remove noop module from tests
Removes the `NoopAnimationsModule` from all tests since it's not necessary in most cases. For the cases where it's relevant, it has been replaced with our own token for disabling animations.
1 parent 4e0ea8e commit cff7f5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+187
-333
lines changed

src/cdk/text-field/autosize.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '@angular/core/testing';
1010
import {FormsModule} from '@angular/forms';
1111
import {By} from '@angular/platform-browser';
12-
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
1312
import {dispatchFakeEvent} from '../testing/private';
1413
import {CdkTextareaAutosize} from './autosize';
1514
import {TextFieldModule} from './text-field-module';
@@ -24,7 +23,6 @@ describe('CdkTextareaAutosize', () => {
2423
imports: [
2524
FormsModule,
2625
TextFieldModule,
27-
NoopAnimationsModule,
2826
AutosizeTextAreaWithContent,
2927
AutosizeTextAreaWithValue,
3028
AutosizeTextareaWithNgModel,

src/material/autocomplete/autocomplete.spec.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ import {
3535
} from '@angular/core/testing';
3636
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
3737
import {By} from '@angular/platform-browser';
38-
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
3938
import {EMPTY, Observable, Subject, Subscription} from 'rxjs';
4039
import {map, startWith} from 'rxjs/operators';
41-
import {MatOption, MatOptionSelectionChange} from '../core';
40+
import {MATERIAL_ANIMATIONS, MatOption, MatOptionSelectionChange} from '../core';
4241
import {MatFormField, MatFormFieldModule} from '../form-field';
4342
import {MatInputModule} from '../input';
4443
import {
@@ -65,10 +64,12 @@ describe('MatAutocomplete', () => {
6564
MatInputModule,
6665
FormsModule,
6766
ReactiveFormsModule,
68-
NoopAnimationsModule,
6967
OverlayModule,
7068
],
71-
providers,
69+
providers: [
70+
...providers,
71+
{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}},
72+
],
7273
declarations: [component],
7374
});
7475

src/material/autocomplete/autocomplete.zone.spec.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import {
1313
} from '@angular/core';
1414
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
1515
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
16-
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
1716
import {Subscription} from 'rxjs';
18-
import {MatOption} from '../core';
17+
import {MATERIAL_ANIMATIONS, MatOption} from '../core';
1918
import {MatFormField, MatFormFieldModule} from '../form-field';
2019
import {MatInputModule} from '../input';
2120
import {MatAutocomplete} from './autocomplete';
@@ -32,10 +31,13 @@ describe('MatAutocomplete Zone.js integration', () => {
3231
MatInputModule,
3332
FormsModule,
3433
ReactiveFormsModule,
35-
NoopAnimationsModule,
3634
OverlayModule,
3735
],
38-
providers: [provideZoneChangeDetection(), ...providers],
36+
providers: [
37+
provideZoneChangeDetection(),
38+
...providers,
39+
{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}},
40+
],
3941
declarations: [component],
4042
});
4143

src/material/autocomplete/testing/autocomplete-harness.spec.ts

-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {Component} from '@angular/core';
22
import {MatAutocompleteModule} from '../module';
33
import {ComponentFixture, TestBed} from '@angular/core/testing';
44
import {HarnessLoader} from '@angular/cdk/testing';
5-
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
65
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
76
import {MatAutocompleteHarness} from './autocomplete-harness';
87

@@ -11,10 +10,6 @@ describe('MatAutocompleteHarness', () => {
1110
let loader: HarnessLoader;
1211

1312
beforeEach(() => {
14-
TestBed.configureTestingModule({
15-
imports: [NoopAnimationsModule, MatAutocompleteModule, AutocompleteHarnessTest],
16-
});
17-
1813
fixture = TestBed.createComponent(AutocompleteHarnessTest);
1914
fixture.detectChanges();
2015
loader = TestbedHarnessEnvironment.loader(fixture);

src/material/bottom-sheet/bottom-sheet.spec.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import {
3030
tick,
3131
} from '@angular/core/testing';
3232
import {By} from '@angular/platform-browser';
33-
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
3433

3534
import {MAT_BOTTOM_SHEET_DEFAULT_OPTIONS, MatBottomSheet} from './bottom-sheet';
3635
import {MAT_BOTTOM_SHEET_DATA, MatBottomSheetConfig} from './bottom-sheet-config';
3736
import {MatBottomSheetModule} from './bottom-sheet-module';
3837
import {MatBottomSheetRef} from './bottom-sheet-ref';
38+
import {MATERIAL_ANIMATIONS} from '../core';
3939

4040
describe('MatBottomSheet', () => {
4141
let bottomSheet: MatBottomSheet;
@@ -50,7 +50,6 @@ describe('MatBottomSheet', () => {
5050
TestBed.configureTestingModule({
5151
imports: [
5252
MatBottomSheetModule,
53-
NoopAnimationsModule,
5453
ComponentWithChildViewContainer,
5554
ComponentWithTemplateRef,
5655
ContentElementDialog,
@@ -60,7 +59,10 @@ describe('MatBottomSheet', () => {
6059
BottomSheetWithInjectedData,
6160
ShadowDomComponent,
6261
],
63-
providers: [{provide: Location, useClass: SpyLocation}],
62+
providers: [
63+
{provide: Location, useClass: SpyLocation},
64+
{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}},
65+
],
6466
});
6567

6668
bottomSheet = TestBed.inject(MatBottomSheet);
@@ -877,7 +879,8 @@ describe('MatBottomSheet with parent MatBottomSheet', () => {
877879

878880
beforeEach(fakeAsync(() => {
879881
TestBed.configureTestingModule({
880-
imports: [MatBottomSheetModule, NoopAnimationsModule, ComponentThatProvidesMatBottomSheet],
882+
imports: [MatBottomSheetModule, ComponentThatProvidesMatBottomSheet],
883+
providers: [{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}}],
881884
});
882885

883886
parentBottomSheet = TestBed.inject(MatBottomSheet);
@@ -957,13 +960,11 @@ describe('MatBottomSheet with default options', () => {
957960
};
958961

959962
TestBed.configureTestingModule({
960-
imports: [
961-
MatBottomSheetModule,
962-
NoopAnimationsModule,
963-
ComponentWithChildViewContainer,
964-
DirectiveWithViewContainer,
963+
imports: [MatBottomSheetModule, ComponentWithChildViewContainer, DirectiveWithViewContainer],
964+
providers: [
965+
{provide: MAT_BOTTOM_SHEET_DEFAULT_OPTIONS, useValue: defaultConfig},
966+
{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}},
965967
],
966-
providers: [{provide: MAT_BOTTOM_SHEET_DEFAULT_OPTIONS, useValue: defaultConfig}],
967968
});
968969

969970
bottomSheet = TestBed.inject(MatBottomSheet);

src/material/bottom-sheet/testing/bottom-sheet-harness.spec.ts

-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
33
import {HarnessLoader} from '@angular/cdk/testing';
44
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
55
import {MatBottomSheet, MatBottomSheetConfig, MatBottomSheetModule} from '../../bottom-sheet';
6-
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
76
import {MatBottomSheetHarness} from './bottom-sheet-harness';
87

98
describe('MatBottomSheetHarness', () => {
109
let fixture: ComponentFixture<BottomSheetHarnessTest>;
1110
let loader: HarnessLoader;
1211

1312
beforeEach(() => {
14-
TestBed.configureTestingModule({
15-
imports: [MatBottomSheetModule, NoopAnimationsModule, BottomSheetHarnessTest],
16-
});
17-
1813
fixture = TestBed.createComponent(BottomSheetHarnessTest);
1914
fixture.detectChanges();
2015
loader = TestbedHarnessEnvironment.documentRootLoader(fixture);

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

+37-23
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {MatFormFieldModule} from '../form-field';
3838
import {MatInputModule} from '../input';
3939
import {By} from '@angular/platform-browser';
4040
import {MatChipEvent, MatChipGrid, MatChipInputEvent, MatChipRow, MatChipsModule} from './index';
41+
import {MATERIAL_ANIMATIONS} from '../core';
4142
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
4243

4344
describe('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

Comments
 (0)