Skip to content

Commit 004afa1

Browse files
authored
test(datepicker/testing): fix test failure (#20304)
Fixes a test failure that is due to a previous fix getting in around the same time as the datepicker harnesses. The problem is that the fix moved the default range selection strategy from the calendar to the range picker which in turn broke the harness unit tests, because they test a standalone calendar. These changes fix the issue by providing a strategy manually for the tests.
1 parent ce72369 commit 004afa1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/material/datepicker/testing/calendar-harness-shared.spec.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import {HarnessLoader} from '@angular/cdk/testing';
22
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
33
import {Component} from '@angular/core';
44
import {ComponentFixture, TestBed} from '@angular/core/testing';
5-
import {MatDatepickerModule, DateRange} from '@angular/material/datepicker';
5+
import {
6+
MatDatepickerModule,
7+
DateRange,
8+
MAT_DATE_RANGE_SELECTION_STRATEGY,
9+
DefaultMatCalendarRangeStrategy,
10+
} from '@angular/material/datepicker';
611
import {MatNativeDateModule} from '@angular/material/core';
712
import {MatCalendarHarness, CalendarView} from './calendar-harness';
813

@@ -20,6 +25,12 @@ export function runCalendarHarnessTests(
2025
await TestBed.configureTestingModule({
2126
imports: [MatNativeDateModule, datepickerModule],
2227
declarations: [CalendarHarnessTest],
28+
providers: [{
29+
// Usually it's the date range picker that provides the default range selection strategy,
30+
// but since we're testing the calendar on its own, we have to provide it manually.
31+
provide: MAT_DATE_RANGE_SELECTION_STRATEGY,
32+
useClass: DefaultMatCalendarRangeStrategy
33+
}]
2334
}).compileComponents();
2435

2536
fixture = TestBed.createComponent(CalendarHarnessTest);

0 commit comments

Comments
 (0)