-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
52 lines (40 loc) · 1.71 KB
/
test.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const rewire = require('rewire');
const app = rewire('./index.js');
const customHelpers = app.__get__('customHelpers');
describe('The formatDate function', () => {
const formatDate = customHelpers.formatDate;
test('it should format full date correctly', () => {
expect(formatDate('2020-12-12')).toBe('12/12/2020');
expect(formatDate('2020-01-12')).toBe('01/12/2020');
expect(formatDate('2020-1-12')).toBe('01/12/2020');
});
test('it should format year with month correctly', () => {
expect(formatDate('2020-12')).toBe('12/2020');
expect(formatDate('2020-01')).toBe('01/2020');
expect(formatDate('2020-1')).toBe('01/2020');
});
test('it should format standalone year correctly', () => {
expect(formatDate('2020')).toBe('2020');
expect(formatDate('1900')).toBe('1900');
expect(formatDate('2222')).toBe('2222');
});
});
describe('The concat function', () => {
const concat = customHelpers.concat;
test('it concatenate multiple strings correctly', () => {
expect(concat('ba', 'na', 'na')).toBe('banana');
expect(concat('Ba', ' T ', 'mAn')).toBe('Ba T mAn');
expect(concat('', ' ', `${(1).toString()}`)).toBe(' 1');
});
test('it concatenate numbers correctly', () => {
expect(concat(1, 2, 3)).toBe('123');
expect(concat(1.1, 2.2, 3.3)).toBe('1.12.23.3');
});
test('it concatenate mixed content correctly', () => {
expect(concat('foo', 2, false)).toBe('foo2false');
expect(concat('undefined', undefined)).toBe('undefinedundefined');
});
test('it omits non primitive data types', () => {
expect(concat({},[], null, function(){})).toBe('');
});
});