Skip to content

Commit 4e564a2

Browse files
committed
Fix no operation tests for datepicker
1 parent 6966881 commit 4e564a2

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
const SUPPORTS_INTL = typeof Intl != 'undefined';
3433

@@ -113,7 +112,7 @@ describe('MatDatepicker', () => {
113112
.not.toBeNull();
114113
});
115114

116-
it('should open datepicker if opened input is set to true', async(() => {
115+
it('should open datepicker if opened input is set to true', () => {
117116
testComponent.opened = true;
118117
fixture.detectChanges();
119118

@@ -122,10 +121,8 @@ describe('MatDatepicker', () => {
122121
testComponent.opened = false;
123122
fixture.detectChanges();
124123

125-
fixture.whenStable().then(() => {
126-
expect(document.querySelector('.mat-datepicker-content')).toBeNull();
127-
});
128-
}));
124+
expect(document.querySelector('.mat-datepicker-content')).toBeNull();
125+
});
129126

130127
it('open in disabled mode should not open the calendar', () => {
131128
testComponent.disabled = true;
@@ -165,9 +162,7 @@ describe('MatDatepicker', () => {
165162
testComponent.datepicker.close();
166163
fixture.detectChanges();
167164

168-
fixture.whenStable().then(() => {
169-
expect(parseInt(getComputedStyle(popup).height as string)).toBe(0);
170-
});
165+
expect(parseInt(getComputedStyle(popup).height as string)).toBe(0);
171166
});
172167

173168
it('should close the popup when pressing ESCAPE', () => {
@@ -191,7 +186,7 @@ describe('MatDatepicker', () => {
191186
.toBe(true, 'Expected default ESCAPE action to be prevented.');
192187
});
193188

194-
it('close should close dialog', () => {
189+
it('close should close dialog', async(() => {
195190
testComponent.touch = true;
196191
fixture.detectChanges();
197192

@@ -206,9 +201,9 @@ describe('MatDatepicker', () => {
206201
fixture.whenStable().then(() => {
207202
expect(document.querySelector('mat-dialog-container')).toBeNull();
208203
});
209-
});
204+
}));
210205

211-
it('setting selected should update input and close calendar', () => {
206+
it('setting selected should update input and close calendar', async(() => {
212207
testComponent.touch = true;
213208
fixture.detectChanges();
214209

@@ -226,12 +221,13 @@ describe('MatDatepicker', () => {
226221
expect(document.querySelector('mat-dialog-container')).toBeNull();
227222
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
228223
});
229-
});
224+
}));
230225

231226
it('clicking the currently selected date should close the calendar ' +
232227
'without firing selectedChanged', () => {
233228
const selectedChangedSpy =
234229
spyOn(testComponent.datepicker.selectedChanged, 'emit').and.callThrough();
230+
235231
for (let changeCount = 1; changeCount < 3; changeCount++) {
236232
const currentDay = changeCount;
237233
testComponent.datepicker.open();
@@ -245,11 +241,9 @@ describe('MatDatepicker', () => {
245241
fixture.detectChanges();
246242
}
247243

248-
fixture.whenStable().then(() => {
249-
expect(selectedChangedSpy.calls.count()).toEqual(1);
250-
expect(document.querySelector('mat-dialog-container')).toBeNull();
251-
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
252-
});
244+
expect(selectedChangedSpy.calls.count()).toEqual(1);
245+
expect(document.querySelector('mat-dialog-container')).toBeNull();
246+
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
253247
});
254248

255249
it('startAt should fallback to input value', () => {
@@ -493,7 +487,7 @@ describe('MatDatepicker', () => {
493487
expect(inputEl.classList).toContain('ng-touched');
494488
});
495489

496-
it('should mark input touched on calendar selection', () => {
490+
it('should mark input touched on calendar selection', async(() => {
497491
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
498492

499493
expect(inputEl.classList).toContain('ng-untouched');
@@ -506,7 +500,7 @@ describe('MatDatepicker', () => {
506500

507501
expect(inputEl.classList).toContain('ng-touched');
508502
});
509-
});
503+
}));
510504
});
511505

512506
describe('datepicker with formControl', () => {
@@ -716,7 +710,7 @@ describe('MatDatepicker', () => {
716710
expect(testComponent.datepicker._maxDate).toEqual(new Date(2020, JAN, 1));
717711
});
718712

719-
it('should mark invalid when value is before min', () => {
713+
it('should mark invalid when value is before min', async(() => {
720714
testComponent.date = new Date(2009, DEC, 31);
721715
fixture.detectChanges();
722716

@@ -726,9 +720,9 @@ describe('MatDatepicker', () => {
726720
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
727721
.toContain('ng-invalid');
728722
});
729-
});
723+
}));
730724

731-
it('should mark invalid when value is after max', () => {
725+
it('should mark invalid when value is after max', async(() => {
732726
testComponent.date = new Date(2020, JAN, 2);
733727
fixture.detectChanges();
734728

@@ -738,9 +732,9 @@ describe('MatDatepicker', () => {
738732
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
739733
.toContain('ng-invalid');
740734
});
741-
});
735+
}));
742736

743-
it('should not mark invalid when value equals min', () => {
737+
it('should not mark invalid when value equals min', async(() => {
744738
testComponent.date = testComponent.datepicker._minDate;
745739
fixture.detectChanges();
746740

@@ -750,9 +744,9 @@ describe('MatDatepicker', () => {
750744
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
751745
.not.toContain('ng-invalid');
752746
});
753-
});
747+
}));
754748

755-
it('should not mark invalid when value equals max', () => {
749+
it('should not mark invalid when value equals max', async(() => {
756750
testComponent.date = testComponent.datepicker._maxDate;
757751
fixture.detectChanges();
758752

@@ -762,9 +756,9 @@ describe('MatDatepicker', () => {
762756
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
763757
.not.toContain('ng-invalid');
764758
});
765-
});
759+
}));
766760

767-
it('should not mark invalid when value is between min and max', () => {
761+
it('should not mark invalid when value is between min and max', async(() => {
768762
testComponent.date = new Date(2010, JAN, 2);
769763
fixture.detectChanges();
770764

@@ -774,7 +768,7 @@ describe('MatDatepicker', () => {
774768
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
775769
.not.toContain('ng-invalid');
776770
});
777-
});
771+
}));
778772
});
779773

780774
describe('datepicker with filter and validation', () => {
@@ -1092,17 +1086,23 @@ describe('MatDatepicker', () => {
10921086
input = fixture.nativeElement.querySelector('input') as HTMLInputElement;
10931087
}));
10941088

1095-
it('should have the correct input value even when inverted date format', () => {
1089+
it('should have the correct input value even when inverted date format', async(() => {
1090+
if (typeof Intl === 'undefined') {
1091+
// Skip this test if the internationalization API is not supported in the current
1092+
// browser. Browsers like Safari 9 do not support the "Intl" API.
1093+
return;
1094+
}
1095+
10961096
let selected = new Date(2017, SEP, 1);
10971097
testComponent.date = selected;
10981098
fixture.detectChanges();
10991099

11001100
fixture.whenStable().then(() => {
11011101
fixture.detectChanges();
1102-
expect(input.value).toBe('01.09.2017');
1102+
expect(input.value).toBe('1.9.2017');
11031103
expect(testComponent.datepickerInput.value).toBe(selected);
11041104
});
1105-
});
1105+
}));
11061106
});
11071107
});
11081108

0 commit comments

Comments
 (0)