forked from jest-community/jest-extended
/
index.test.js
41 lines (34 loc) 路 1000 Bytes
/
index.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
import each from 'jest-each';
import matcher from './';
expect.extend(matcher);
describe('.toBeValidDate', () => {
test('passes when given a valid date', () => {
expect(new Date()).toBeValidDate();
});
test('fails when given an invalid date', () => {
expect(() => expect(new Date('01/90/2017')).toBeValidDate()).toThrowErrorMatchingSnapshot();
});
test('fails when not given non-date values', () => {
expect(() => expect(1).toBeValidDate()).toThrowErrorMatchingSnapshot();
});
});
describe('.not.toBeValidDate', () => {
each([
[new Date('01/90/2018')],
[new Date('32/01/2018')],
[false],
[true],
[0],
[''],
[{}],
[() => {}],
[undefined],
[null],
[NaN]
]).test('passes when not given a date: %s', given => {
expect(given).not.toBeValidDate();
});
test('fails when not given a valid date value', () => {
expect(() => expect(new Date('01/01/2018')).not.toBeValidDate()).toThrowErrorMatchingSnapshot();
});
});