Skip to content

Commit 80038f0

Browse files
committed
throw 'Invalid Date'
1 parent c6155ee commit 80038f0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/services/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export function getCalendarDateString(date?: Date | string | number) {
1212
} else if (isNumber(date)) {
1313
return toMarkingFormat(new XDate(date, true));
1414
}
15-
return 'Invalid Date';
15+
throw 'Invalid Date';
1616
}
1717
}

src/services/services.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ describe('services', function () {
44
describe('getCalendarDateString()', function () {
55
const timestamp = 1585561899000;
66
const expectedFormattedDate = '2020-03-30';
7-
const invalidString = 'Invalid Date';
7+
const throwMessage = 'Invalid Date';
88
const epochDate = '1970-01-01';
99

1010
it('should return undefined for undefined date', function () {
@@ -19,8 +19,8 @@ describe('services', function () {
1919
expect(getCalendarDateString(new Date('30 Mar 2020'))).toEqual(expectedFormattedDate);
2020
});
2121

22-
it('should return "Invalid Date" for invalid JS Date', function () {
23-
expect(getCalendarDateString(new Date('30/03/2020'))).toEqual(invalidString);
22+
it('should throw "Invalid Date" for invalid JS Date', function () {
23+
expect(() => {getCalendarDateString(new Date('30/03/2020'));}).toThrow(throwMessage);
2424
});
2525

2626
it('should return dashed date for timestamp number', function () {
@@ -40,7 +40,7 @@ describe('services', function () {
4040
});
4141

4242
it('should return "Invalid Date" for invalid date string', function () {
43-
expect(getCalendarDateString('30/3/2020')).toEqual(invalidString);
43+
expect(getCalendarDateString('30/3/2020')).toEqual(throwMessage);
4444
});
4545
});
4646
});

0 commit comments

Comments
 (0)