Skip to content

Commit 8f7292f

Browse files
authored
test: replace native date module with provider function (#32114)
Replaces the usages of `MatNativeDateModule` with the `provideNativeDateAdapter` function.
1 parent 03c5d34 commit 8f7292f

14 files changed

+135
-125
lines changed

src/components-examples/material/datepicker/datepicker-harness/datepicker-harness-example.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
33
import {MatDatepickerInputHarness} from '@angular/material/datepicker/testing';
44
import {HarnessLoader} from '@angular/cdk/testing';
55
import {DatepickerHarnessExample} from './datepicker-harness-example';
6-
import {MATERIAL_ANIMATIONS, MatNativeDateModule} from '@angular/material/core';
6+
import {MATERIAL_ANIMATIONS, provideNativeDateAdapter} from '@angular/material/core';
77

88
describe('DatepickerHarnessExample', () => {
99
let fixture: ComponentFixture<DatepickerHarnessExample>;
1010
let loader: HarnessLoader;
1111

1212
beforeEach(() => {
1313
TestBed.configureTestingModule({
14-
imports: [MatNativeDateModule],
15-
providers: [{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}}],
14+
providers: [
15+
provideNativeDateAdapter(),
16+
{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}},
17+
],
1618
});
1719
fixture = TestBed.createComponent(DatepickerHarnessExample);
1820
fixture.detectChanges();

src/components-examples/material/timepicker/timepicker-harness/timepicker-harness-example.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
33
import {MatTimepickerInputHarness} from '@angular/material/timepicker/testing';
44
import {HarnessLoader} from '@angular/cdk/testing';
55
import {TimepickerHarnessExample} from './timepicker-harness-example';
6-
import {DateAdapter, MATERIAL_ANIMATIONS, MatNativeDateModule} from '@angular/material/core';
6+
import {DateAdapter, MATERIAL_ANIMATIONS, provideNativeDateAdapter} from '@angular/material/core';
77

88
describe('TimepickerHarnessExample', () => {
99
let fixture: ComponentFixture<TimepickerHarnessExample>;
1010
let loader: HarnessLoader;
1111

1212
beforeEach(() => {
1313
TestBed.configureTestingModule({
14-
imports: [MatNativeDateModule],
15-
providers: [{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}}],
14+
providers: [
15+
provideNativeDateAdapter(),
16+
{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}},
17+
],
1618
});
1719
TestBed.inject(DateAdapter).setLocale('en-US'); // Set the locale to en-US to guarantee consistent tests.
1820
fixture = TestBed.createComponent(TimepickerHarnessExample);

src/material/datepicker/calendar-header.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {provideFakeDirectionality} from '@angular/cdk/testing/private';
22
import {Component} from '@angular/core';
33
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
44
import {By} from '@angular/platform-browser';
5-
import {DateAdapter, MatNativeDateModule} from '../core';
5+
import {DateAdapter, provideNativeDateAdapter} from '../core';
66
import {DEC, FEB, JAN} from '../testing';
77
import {MatCalendar} from './calendar';
88
import {MatDatepickerIntl} from './datepicker-intl';
@@ -12,8 +12,8 @@ import {yearsPerPage} from './multi-year-view';
1212
describe('MatCalendarHeader', () => {
1313
beforeEach(waitForAsync(() => {
1414
TestBed.configureTestingModule({
15-
imports: [MatNativeDateModule, MatDatepickerModule],
16-
providers: [MatDatepickerIntl, provideFakeDirectionality('ltr')],
15+
imports: [MatDatepickerModule],
16+
providers: [MatDatepickerIntl, provideFakeDirectionality('ltr'), provideNativeDateAdapter()],
1717
});
1818
}));
1919

@@ -378,7 +378,7 @@ describe('MatCalendarHeader', () => {
378378
(yearSelected)="selectedYear=$event"
379379
(monthSelected)="selectedMonth=$event">
380380
</mat-calendar>`,
381-
imports: [MatNativeDateModule, MatDatepickerModule],
381+
imports: [MatDatepickerModule],
382382
})
383383
class StandardCalendar {
384384
selected: Date;
@@ -395,7 +395,7 @@ class StandardCalendar {
395395
[maxDate]="maxDate">
396396
</mat-calendar>
397397
`,
398-
imports: [MatNativeDateModule, MatDatepickerModule],
398+
imports: [MatDatepickerModule],
399399
})
400400
class CalendarWithMinMaxDate {
401401
startAt = new Date(2018, JAN, 1);

src/material/datepicker/date-range-input.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
Validators,
2020
} from '@angular/forms';
2121
import {Subscription} from 'rxjs';
22-
import {ErrorStateMatcher, MATERIAL_ANIMATIONS, MatNativeDateModule} from '../core';
22+
import {ErrorStateMatcher, MATERIAL_ANIMATIONS, provideNativeDateAdapter} from '../core';
2323
import {MatFormField, MatFormFieldModule, MatLabel} from '../form-field';
2424
import {MatInputModule} from '../input';
2525
import {MatDateRangeInput} from './date-range-input';
@@ -36,11 +36,11 @@ describe('MatDateRangeInput', () => {
3636
MatFormFieldModule,
3737
MatInputModule,
3838
ReactiveFormsModule,
39-
MatNativeDateModule,
4039
component,
4140
],
4241
providers: [
4342
...providers,
43+
provideNativeDateAdapter(),
4444
{provide: MATERIAL_ANIMATIONS, useValue: {animationsDisabled: true}},
4545
],
4646
});

src/material/datepicker/date-range-selection-strategy.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {TestBed} from '@angular/core/testing';
2-
import {MatNativeDateModule} from '../core';
2+
import {provideNativeDateAdapter} from '../core';
33

44
import {JAN, FEB, MAR} from '../testing';
55
import {
@@ -13,8 +13,8 @@ describe('DefaultMatCalendarRangeStrategy', () => {
1313

1414
beforeEach(() => {
1515
TestBed.configureTestingModule({
16-
imports: [MatNativeDateModule],
1716
providers: [
17+
provideNativeDateAdapter(),
1818
{provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: DefaultMatCalendarRangeStrategy},
1919
],
2020
});

0 commit comments

Comments
 (0)