Skip to content

Commit 2bf77c7

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

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

src/lib/datepicker/datepicker.spec.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('MatDatepicker', () => {
104104
.not.toBeNull();
105105
});
106106

107-
it('should open datepicker if opened input is set to true', async(() => {
107+
it('should open datepicker if opened input is set to true', () => {
108108
testComponent.opened = true;
109109
fixture.detectChanges();
110110

@@ -113,10 +113,8 @@ describe('MatDatepicker', () => {
113113
testComponent.opened = false;
114114
fixture.detectChanges();
115115

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

121119
it('open in disabled mode should not open the calendar', () => {
122120
testComponent.disabled = true;
@@ -156,9 +154,7 @@ describe('MatDatepicker', () => {
156154
testComponent.datepicker.close();
157155
fixture.detectChanges();
158156

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

164160
it('should close the popup when pressing ESCAPE', () => {
@@ -182,7 +178,7 @@ describe('MatDatepicker', () => {
182178
.toBe(true, 'Expected default ESCAPE action to be prevented.');
183179
});
184180

185-
it('close should close dialog', () => {
181+
it('close should close dialog', async(() => {
186182
testComponent.touch = true;
187183
fixture.detectChanges();
188184

@@ -197,9 +193,9 @@ describe('MatDatepicker', () => {
197193
fixture.whenStable().then(() => {
198194
expect(document.querySelector('mat-dialog-container')).toBeNull();
199195
});
200-
});
196+
}));
201197

202-
it('setting selected should update input and close calendar', () => {
198+
it('setting selected should update input and close calendar', async(() => {
203199
testComponent.touch = true;
204200
fixture.detectChanges();
205201

@@ -217,12 +213,13 @@ describe('MatDatepicker', () => {
217213
expect(document.querySelector('mat-dialog-container')).toBeNull();
218214
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
219215
});
220-
});
216+
}));
221217

222218
it('clicking the currently selected date should close the calendar ' +
223219
'without firing selectedChanged', () => {
224220
const selectedChangedSpy =
225221
spyOn(testComponent.datepicker.selectedChanged, 'emit').and.callThrough();
222+
226223
for (let changeCount = 1; changeCount < 3; changeCount++) {
227224
const currentDay = changeCount;
228225
testComponent.datepicker.open();
@@ -236,11 +233,9 @@ describe('MatDatepicker', () => {
236233
fixture.detectChanges();
237234
}
238235

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-
});
236+
expect(selectedChangedSpy.calls.count()).toEqual(1);
237+
expect(document.querySelector('mat-dialog-container')).toBeNull();
238+
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2));
244239
});
245240

246241
it('startAt should fallback to input value', () => {
@@ -488,7 +483,7 @@ describe('MatDatepicker', () => {
488483
expect(inputEl.classList).toContain('ng-touched');
489484
});
490485

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

494489
expect(inputEl.classList).toContain('ng-untouched');
@@ -501,7 +496,7 @@ describe('MatDatepicker', () => {
501496

502497
expect(inputEl.classList).toContain('ng-touched');
503498
});
504-
});
499+
}));
505500
});
506501

507502
describe('datepicker with formControl', () => {
@@ -711,7 +706,7 @@ describe('MatDatepicker', () => {
711706
expect(testComponent.datepicker._maxDate).toEqual(new Date(2020, JAN, 1));
712707
});
713708

714-
it('should mark invalid when value is before min', () => {
709+
it('should mark invalid when value is before min', async(() => {
715710
testComponent.date = new Date(2009, DEC, 31);
716711
fixture.detectChanges();
717712

@@ -721,9 +716,9 @@ describe('MatDatepicker', () => {
721716
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
722717
.toContain('ng-invalid');
723718
});
724-
});
719+
}));
725720

726-
it('should mark invalid when value is after max', () => {
721+
it('should mark invalid when value is after max', async(() => {
727722
testComponent.date = new Date(2020, JAN, 2);
728723
fixture.detectChanges();
729724

@@ -733,9 +728,9 @@ describe('MatDatepicker', () => {
733728
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
734729
.toContain('ng-invalid');
735730
});
736-
});
731+
}));
737732

738-
it('should not mark invalid when value equals min', () => {
733+
it('should not mark invalid when value equals min', async(() => {
739734
testComponent.date = testComponent.datepicker._minDate;
740735
fixture.detectChanges();
741736

@@ -745,9 +740,9 @@ describe('MatDatepicker', () => {
745740
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
746741
.not.toContain('ng-invalid');
747742
});
748-
});
743+
}));
749744

750-
it('should not mark invalid when value equals max', () => {
745+
it('should not mark invalid when value equals max', async(() => {
751746
testComponent.date = testComponent.datepicker._maxDate;
752747
fixture.detectChanges();
753748

@@ -757,9 +752,9 @@ describe('MatDatepicker', () => {
757752
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
758753
.not.toContain('ng-invalid');
759754
});
760-
});
755+
}));
761756

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

@@ -769,7 +764,7 @@ describe('MatDatepicker', () => {
769764
expect(fixture.debugElement.query(By.css('input')).nativeElement.classList)
770765
.not.toContain('ng-invalid');
771766
});
772-
});
767+
}));
773768
});
774769

775770
describe('datepicker with filter and validation', () => {
@@ -1057,17 +1052,17 @@ describe('MatDatepicker', () => {
10571052
input = fixture.nativeElement.querySelector('input') as HTMLInputElement;
10581053
}));
10591054

1060-
it('should have the correct input value even when inverted date format', () => {
1055+
it('should have the correct input value even when inverted date format', async(() => {
10611056
let selected = new Date(2017, SEP, 1);
10621057
testComponent.date = selected;
10631058
fixture.detectChanges();
10641059

10651060
fixture.whenStable().then(() => {
10661061
fixture.detectChanges();
1067-
expect(input.value).toBe('01.09.2017');
1062+
expect(input.value).toBe('1.9.2017');
10681063
expect(testComponent.datepickerInput.value).toBe(selected);
10691064
});
1070-
});
1065+
}));
10711066
});
10721067
});
10731068

0 commit comments

Comments
 (0)