-
Notifications
You must be signed in to change notification settings - Fork 960
/
Copy pathdateFnsDate.service.spec.ts
66 lines (51 loc) · 2.08 KB
/
dateFnsDate.service.spec.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/
import { DateService } from '@ui-kitten/components';
import { DateFnsService } from './dateFnsDate.service';
describe('@date-fns: service checks', () => {
let dateService: DateService<Date>;
beforeEach(() => {
dateService = new DateFnsService('en', null);
});
it('* should parse date according to the MM.dd.yyyy format', () => {
const date = '06.15.2018';
expect(dateService.parse(date, 'MM.dd.yyyy')).toEqual(new Date(2018, 5, 15));
});
it('* should not format if date isn\'t passed', () => {
expect(() => dateService.format(undefined, 'dd.MM.YYYY')).not.toThrow();
expect(dateService.format(undefined, 'dd.MM.YYYY')).toEqual('');
});
describe('service global config', () => {
const FORMAT = 'MM-dd-yyyy';
const year = 2010;
const monthIndex = 10;
const month: number = monthIndex + 1;
const day = 20;
const date: Date = new Date(year, monthIndex, day);
const formattedDate = `${month}-${day}-${year}`;
beforeEach(() => {
dateService = new DateFnsService('en', {
format: FORMAT,
});
});
it('* should use format from global config if isn\'t passed as parameter', () => {
expect(dateService.format(date, undefined)).toEqual(formattedDate);
const parsedDate = dateService.parse(formattedDate, '');
expect(parsedDate.valueOf()).toEqual(date.valueOf());
});
it('* should use parameter over global config format if presented', () => {
expect(dateService.format(date, undefined)).toEqual(formattedDate);
const parsedDate = dateService.parse(formattedDate, FORMAT);
expect(parsedDate.valueOf()).toEqual(date.valueOf());
});
it('* should pass parseOptions to parse function', () => {
expect(dateService.parse(formattedDate, '')).toEqual(date);
});
it('* should pass formatOptions to format function', () => {
expect(dateService.format(date, 'dd/MM/yyyy')).toEqual('20/11/2010');
});
});
});