Skip to content

Commit e6e374d

Browse files
hansireitlexasq
andauthored
test(timepicker): fix silently failing unit-tests (#6628)
Unit-tests that cannot fail are useless, therefore this fix * unit test now fail if the expected value does not match * remove duplicated unit test Closes #6545 Co-authored-by: Alexey Umanskiy <[email protected]>
1 parent 4a8a35e commit e6e374d

File tree

1 file changed

+12
-40
lines changed

1 file changed

+12
-40
lines changed

src/datepicker/testing/bs-daterangepicker.spec.ts

+12-40
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
77
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
88
import { By } from '@angular/platform-browser';
99
import { BsCustomDates } from '../themes/bs/bs-custom-dates-view.component';
10+
import { firstValueFrom } from 'rxjs';
1011

1112
@Component({
1213
selector: 'test-cmp',
@@ -87,7 +88,7 @@ describe('daterangepicker:', () => {
8788
expect(timepickerZone).not.toBeTruthy();
8889
});
8990

90-
it('should update time when time is changed in timepicker', () => {
91+
it('should update time when time is changed in timepicker', (done) => {
9192
const directive = getDaterangepickerDirective(fixture);
9293
directive.bsConfig = {
9394
withTimepicker: true
@@ -119,6 +120,7 @@ describe('daterangepicker:', () => {
119120
.subscribe(view => {
120121
expect(view[0].getMinutes()).toEqual(ranges[1].value[0].getMinutes());
121122
expect(view[1].getMinutes()).toEqual(ranges[1].value[1].getMinutes());
123+
done();
122124
});
123125
});
124126

@@ -185,7 +187,7 @@ describe('daterangepicker:', () => {
185187
expect(getDaterangepickerContainer(datepicker)).toBeNull();
186188
});
187189

188-
it('should display correct date range in input when selected from ranges', () => {
190+
it('should display correct date range in input when selected from ranges', (done) => {
189191
const datepicker = showDatepicker(fixture);
190192
const ranges = [
191193
{
@@ -207,6 +209,7 @@ describe('daterangepicker:', () => {
207209
.select(state => state.selectedRange)
208210
.subscribe(view => {
209211
expect(view).toEqual(ranges[0].value);
212+
done();
210213
});
211214
});
212215

@@ -230,31 +233,6 @@ describe('daterangepicker:', () => {
230233

231234
const rangesButton = document.querySelector('.bs-datepicker-predefined-btns');
232235
expect(rangesButton.childElementCount).toEqual(ranges.length);
233-
234-
});
235-
236-
it('should display correct date range in input when selected from ranges', () => {
237-
const datepicker = showDatepicker(fixture);
238-
const ranges = [
239-
{
240-
label: 'Last 7 days',
241-
value: [new Date('12-10-2019'), new Date('12-16-2019')]
242-
},
243-
{
244-
label: 'Next 7 days',
245-
value: [new Date('12-16-2019'), new Date('12-22-2019')]
246-
}
247-
];
248-
datepicker.bsConfig.ranges = ranges;
249-
const datepickerContainerInstance = getDaterangepickerContainer(datepicker);
250-
datepickerContainerInstance.setRangeOnCalendar(ranges[0]);
251-
252-
fixture.detectChanges();
253-
datepickerContainerInstance[`_store`]
254-
.select(state => state.selectedRange)
255-
.subscribe(view => {
256-
expect(view).toEqual(ranges[0].value);
257-
});
258236
});
259237

260238
it('should correctly display the selected range button with active custom class', () => {
@@ -286,7 +264,7 @@ describe('daterangepicker:', () => {
286264
expect(activeRangeButton[0].innerHTML.trim()).toEqual(ranges[0].label);
287265
});
288266

289-
it('should not allow to select date behind max value', () => {
267+
it('should not allow to select date behind max value', async () => {
290268
const datepicker = showDatepicker(fixture);
291269
datepicker.bsConfig.maxDate = new Date();
292270
datepicker.bsConfig.maxDateRange = 10;
@@ -300,15 +278,12 @@ describe('daterangepicker:', () => {
300278
value: [correctDateStart, correctDateEnd]
301279
};
302280

303-
datepickerContainerInstance.setMaxDateRangeOnCalendar(correctDateStart);
281+
datepickerContainerInstance.setMaxDateRangeOnCalendar(correctDateEnd);
304282
datepickerContainerInstance.setRangeOnCalendar(selectedRange);
305283
fixture.detectChanges();
306284

307-
datepickerContainerInstance[`_store`]
308-
.select(state => state)
309-
.subscribe(view => {
310-
expect(view.maxDate).toEqual(correctDateEnd);
311-
});
285+
let view = await firstValueFrom(datepickerContainerInstance[`_store`].select((state) => state));
286+
expect(view.maxDate).toEqual(correctDateEnd);
312287

313288
const incorrectCaseStart = new Date(new Date().setDate(new Date().getDate() - 5));
314289
const incorrectCaseEnd = new Date(new Date().setDate(new Date().getDate() + 15));
@@ -321,10 +296,7 @@ describe('daterangepicker:', () => {
321296
datepickerContainerInstance.setRangeOnCalendar(selectedRange1);
322297
fixture.detectChanges();
323298

324-
datepickerContainerInstance[`_store`]
325-
.select(state => state)
326-
.subscribe(view => {
327-
expect(view.maxDate).not.toEqual(incorrectCaseEnd);
328-
});
329-
});
299+
view = await firstValueFrom(datepickerContainerInstance[`_store`].select((state) => state));
300+
expect(view.maxDate).not.toEqual(incorrectCaseEnd);
330301
});
302+
});

0 commit comments

Comments
 (0)