-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathutils.test.js
73 lines (63 loc) · 1.79 KB
/
utils.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { isDate, isEmpty, isObject } from '../src/utils';
describe('utils', () => {
describe('.isDate', () => {
test.each([
[new Date()],
[new Date('2016')],
[new Date('2016-01')],
[new Date('2016-01-01')],
[new Date('2016-01-01:14:45:20')],
[new Date('Tue Feb 14 2017 14:45:20 GMT+0000 (GMT)')],
[new Date('nonsense')],
])('returns true when given a date object of %s', (date) => {
expect(isDate(date)).toBe(true);
});
test.each([
[100],
['100'],
[false],
[{ a: 100 }],
[[100, 101, 102]],
[Date.parse('2016')],
[Date.now()],
])('returns false when not given a date object of %s', (x) => {
expect(isDate(x)).toBe(false);
});
});
describe('.isEmpty', () => {
describe('returns true', () => {
test('when given an empty object', () => {
expect(isEmpty({})).toBe(true);
});
test('when given an empty array', () => {
expect(isEmpty([])).toBe(true);
});
});
describe('returns false', () => {
test('when given an empty object', () => {
expect(isEmpty({ a: 1 })).toBe(false);
});
test('when given an empty array', () => {
expect(isEmpty([1])).toBe(false);
});
});
});
describe('.isObject', () => {
test('returns true when value is an object', () => {
expect(isObject({})).toBe(true);
});
test('returns true when value is an array', () => {
expect(isObject([])).toBe(true);
});
test.each([
['int', 1],
['string', 'a'],
['boolean', true],
['null', null],
['undefined', undefined],
['function', () => ({})],
])('returns false when value is of type: %s', (type, value) => {
expect(isObject(value)).toBe(false);
});
});
});