Skip to content

Commit

Permalink
test: add tests for toDateString
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Sep 18, 2021
1 parent 3f21db2 commit f16c64d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/helpers/to-date-string.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export function toDateString(date: Date): string {
try {
const dateString = date.toJSON();
return dateString == null ? '' : dateString.replace(/^(.+)T.+/i, '$1');
} catch {
return '';
}
}
return date.toISOString().replace(/^(.+)T.+/i, '$1');
}
13 changes: 13 additions & 0 deletions src/tests/helpers/to-date-string.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from '@open-wc/testing';

import { toDateString } from '../../helpers/to-date-string';

describe(toDateString.name, () => {
it('returns date string', () => {
const testDateStr = '2020-02-02';

const result = toDateString(new Date(testDateStr));

expect(result).equal(testDateStr);
});
});

0 comments on commit f16c64d

Please sign in to comment.