Skip to content

Commit a38f138

Browse files
committed
Fix no operation tests for datepicker
1 parent 54dbc6b commit a38f138

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/lib/datepicker/datepicker.spec.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {MatDatepickerInput} from './datepicker-input';
2828
import {MatDatepickerToggle} from './datepicker-toggle';
2929
import {MatDatepickerIntl, MatDatepickerModule} from './index';
3030

31-
3231
describe('MatDatepicker', () => {
3332
afterEach(inject([OverlayContainer], (container: OverlayContainer) => {
3433
container.getContainerElement().parentNode!.removeChild(container.getContainerElement());
@@ -104,7 +103,7 @@ describe('MatDatepicker', () => {
104103
.not.toBeNull();
105104
});
106105

107-
it('should open datepicker if opened input is set to true', async(() => {
106+
it('should open datepicker if opened input is set to true', () => {
108107
testComponent.opened = true;
109108
fixture.detectChanges();
110109

@@ -113,10 +112,8 @@ describe('MatDatepicker', () => {
113112
testComponent.opened = false;
114113
fixture.detectChanges();
115114

116-
fixture.whenStable().then(() => {
117-
expect(document.querySelector('.mat-datepicker-content')).toBeNull();
118-
});
119-
}));
115+
expect(document.querySelector('.mat-datepicker-content')).toBeNull();
116+
});
120117

121118
it('open in disabled mode should not open the calendar', () => {
122119
testComponent.disabled = true;
@@ -156,9 +153,7 @@ describe('MatDatepicker', () => {
156153
testComponent.datepicker.close();
157154
fixture.detectChanges();
158155

159-
fixture.whenStable().then(() => {
160-
expect(parseInt(getComputedStyle(popup).height as string)).toBe(0);
161-
});
156+
expect(parseInt(getComputedStyle(popup).height as string)).toBe(0);
162157
});
163158

164159
it('should close the popup when pressing ESCAPE', () => {
@@ -182,7 +177,7 @@ describe('MatDatepicker', () => {
182177
.toBe(true, 'Expected default ESCAPE action to be prevented.');
183178
});
184179

185-
it('close should close dialog', () => {
180+
it('close should close dialog', async(() => {
186181
testComponent.touch = true;
187182
fixture.detectChanges();
188183

@@ -197,9 +192,9 @@ describe('MatDatepicker', () => {
197192
fixture.whenStable().then(() => {
198193
expect(document.querySelector('mat-dialog-container')).toBeNull();
199194
});
200-
});
195+
}));
201196

202-
it('setting selected should update input and close calendar', () => {
197+
it('setting selected should update input and close calendar', async(() => {
203198
testComponent.touch = true;
204199
fixture.detectChanges();
205200

@@ -217,12 +212,13 @@ describe('MatDatepicker', () => {
217212
expect(document.querySelector('mat-dialog-container')).toBeNull();
218213
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
219214
});
220-
});
215+
}));
221216

222217
it('clicking the currently selected date should close the calendar ' +
223218
'without firing selectedChanged', () => {
224219
const selectedChangedSpy =
225220
spyOn(testComponent.datepicker.selectedChanged, 'emit').and.callThrough();
221+
226222
for (let changeCount = 1; changeCount < 3; changeCount++) {
227223
const currentDay = changeCount;
228224
testComponent.datepicker.open();
@@ -236,11 +232,9 @@ describe('MatDatepicker', () => {
236232
fixture.detectChanges();
237233
}
238234

239-
fixture.whenStable().then(() => {
240-
expect(selectedChangedSpy.calls.count()).toEqual(1);
241-
expect(document.querySelector('mat-dialog-container')).toBeNull();
242-
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
243-
});
235+
expect(selectedChangedSpy.calls.count()).toEqual(1);
236+
expect(document.querySelector('mat-dialog-container')).toBeNull();
237+
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
244238
});
245239

246240
it('startAt should fallback to input value', () => {
@@ -488,7 +482,7 @@ describe('MatDatepicker', () => {
488482
expect(inputEl.classList).toContain('ng-touched');
489483
});
490484

491-
it('should mark input touched on calendar selection', () => {
485+
it('should mark input touched on calendar selection', async(() => {
492486
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
493487

494488
expect(inputEl.classList).toContain('ng-untouched');
@@ -501,7 +495,7 @@ describe('MatDatepicker', () => {
501495

502496
expect(inputEl.classList).toContain('ng-touched');
503497
});
504-
});
498+
}));
505499
});
506500

507501
describe('datepicker with formControl', () => {
@@ -711,7 +705,7 @@ describe('MatDatepicker', () => {
711705
expect(testComponent.datepicker._maxDate).toEqual(new Date(2020, JAN, 1));
712706
});
713707

714-
it('should mark invalid when value is before min', () => {
708+
it('should mark invalid when value is before min', async(() => {
715709
testComponent.date = new Date(2009, DEC, 31);
716710
fixture.detectChanges();
717711

@@ -721,9 +715,9 @@ describe('MatDatepicker', () => {
721715
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
722716
.toContain('ng-invalid');
723717
});
724-
});
718+
}));
725719

726-
it('should mark invalid when value is after max', () => {
720+
it('should mark invalid when value is after max', async(() => {
727721
testComponent.date = new Date(2020, JAN, 2);
728722
fixture.detectChanges();
729723

@@ -733,9 +727,9 @@ describe('MatDatepicker', () => {
733727
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
734728
.toContain('ng-invalid');
735729
});
736-
});
730+
}));
737731

738-
it('should not mark invalid when value equals min', () => {
732+
it('should not mark invalid when value equals min', async(() => {
739733
testComponent.date = testComponent.datepicker._minDate;
740734
fixture.detectChanges();
741735

@@ -745,9 +739,9 @@ describe('MatDatepicker', () => {
745739
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
746740
.not.toContain('ng-invalid');
747741
});
748-
});
742+
}));
749743

750-
it('should not mark invalid when value equals max', () => {
744+
it('should not mark invalid when value equals max', async(() => {
751745
testComponent.date = testComponent.datepicker._maxDate;
752746
fixture.detectChanges();
753747

@@ -757,9 +751,9 @@ describe('MatDatepicker', () => {
757751
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
758752
.not.toContain('ng-invalid');
759753
});
760-
});
754+
}));
761755

762-
it('should not mark invalid when value is between min and max', () => {
756+
it('should not mark invalid when value is between min and max', async(() => {
763757
testComponent.date = new Date(2010, JAN, 2);
764758
fixture.detectChanges();
765759

@@ -769,7 +763,7 @@ describe('MatDatepicker', () => {
769763
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
770764
.not.toContain('ng-invalid');
771765
});
772-
});
766+
}));
773767
});
774768

775769
describe('datepicker with filter and validation', () => {
@@ -1057,17 +1051,23 @@ describe('MatDatepicker', () => {
10571051
input = fixture.nativeElement.querySelector('input') as HTMLInputElement;
10581052
}));
10591053

1060-
it('should have the correct input value even when inverted date format', () => {
1054+
it('should have the correct input value even when inverted date format', async(() => {
1055+
if (typeof Intl === 'undefined') {
1056+
// Skip this test if the internationalization API is not supported in the current
1057+
// browser. Browsers like Safari 9 do not support the "Intl" API.
1058+
return;
1059+
}
1060+
10611061
let selected = new Date(2017, SEP, 1);
10621062
testComponent.date = selected;
10631063
fixture.detectChanges();
10641064

10651065
fixture.whenStable().then(() => {
10661066
fixture.detectChanges();
1067-
expect(input.value).toBe('01.09.2017');
1067+
expect(input.value).toBe('1.9.2017');
10681068
expect(testComponent.datepickerInput.value).toBe(selected);
10691069
});
1070-
});
1070+
}));
10711071
});
10721072
});
10731073

0 commit comments

Comments
 (0)