-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtoLocalizedDateString_spec.js
35 lines (29 loc) · 1.28 KB
/
toLocalizedDateString_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import moment from 'moment';
import { expect } from 'chai';
import toLocalizedDateString from '../../src/utils/toLocalizedDateString';
import { ISO_FORMAT } from '../../src/constants';
describe('toLocalizedDateString', () => {
it('returns null for falsy argument', () => {
expect(toLocalizedDateString()).to.equal(null);
});
it('converts moment object to localized date string', () => {
const testDate = moment('1991-07-13');
const dateString = toLocalizedDateString(testDate);
expect(dateString).to.equal(testDate.format('L'));
});
it('converts iso date string to localized date string', () => {
const testDate = moment('1991-07-13');
const dateString = toLocalizedDateString(testDate.format(ISO_FORMAT));
expect(dateString).to.equal(testDate.format('L'));
});
it('localized date strings stay the same', () => {
const testDate = moment('1991-07-13');
const dateString = toLocalizedDateString(testDate.format('L'));
expect(dateString).to.equal(testDate.format('L'));
});
it('converts custom format date strings with format passed in', () => {
const testDate = moment('1991-07-13');
const dateString = toLocalizedDateString(testDate.format('YYYY---DD/MM'), 'YYYY---DD/MM');
expect(dateString).to.equal(testDate.format('L'));
});
});