Skip to content

Commit

Permalink
test(datepicker/testing): fix test failure (#20304)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto committed Aug 14, 2020
1 parent ce72369 commit 004afa1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/material/datepicker/testing/calendar-harness-shared.spec.ts
Expand Up @@ -2,7 +2,12 @@ import {HarnessLoader} from '@angular/cdk/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {Component} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {MatDatepickerModule, DateRange} from '@angular/material/datepicker';
import {
MatDatepickerModule,
DateRange,
MAT_DATE_RANGE_SELECTION_STRATEGY,
DefaultMatCalendarRangeStrategy,
} from '@angular/material/datepicker';
import {MatNativeDateModule} from '@angular/material/core';
import {MatCalendarHarness, CalendarView} from './calendar-harness';

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

fixture = TestBed.createComponent(CalendarHarnessTest);
Expand Down

0 comments on commit 004afa1

Please sign in to comment.