Skip to content

Commit 05e8555

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 05e8555

File tree

52 files changed

+184
-332
lines changed

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

+184
-332
lines changed

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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 6 additions & 4 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 11 additions & 10 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 36 additions & 23 deletions
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

@@ -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

Comments
 (0)