-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
index.test.js
67 lines (56 loc) 路 1.77 KB
/
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
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
import * as fs from 'fs';
import * as path from 'path';
import * as matchers from './index';
expect.extend(matchers);
// This does not test all matchers, just couple random ones to check
// if imports work correctly.
describe('positive matcher', () => {
test('.toBeEven', () => {
expect(2).toBeEven();
});
});
describe('negative matcher', () => {
test('.not.toBeWithin', () => {
expect(1).not.toBeWithin(10, 20);
});
});
describe('asymmetric matchers', () => {
describe('positive matchers', () => {
test('.toSatisfy', () => {
expect(4).toEqual(expect.toSatisfy(num => num === 4));
});
test('.toEqual', () => {
expect([]).toEqual(expect.toBeArray());
});
});
describe('negative matchers', () => {
test('not.toInclude', () => {
const data = 'bob';
expect(data).not.toEqual(expect.toInclude('alice'));
expect(data).toEqual(expect.not.toInclude('alice'));
});
test('not.toContainKey', () => {
const data = { hello: 'world' };
expect(data).not.toEqual(expect.toContainKey('foo'));
expect('bob').toEqual(expect.not.toInclude('foo'));
});
});
});
describe('all matchers', () => {
test('must be exported', () => {
const directories = fs.readdirSync(__dirname).filter(dir => fs.statSync(path.join(__dirname, dir)).isDirectory());
const namedMatchers = Object.keys(matchers);
try {
expect(namedMatchers).toHaveLength(directories.length);
} catch (error) {
const missing = new Set(directories.filter(dir => !namedMatchers.includes(dir)));
console.error('Missing', missing);
throw error;
}
});
describe('must be functions', () => {
test.each(Object.entries(matchers))('%s', (_, matcher) => {
expect(typeof matcher).toBe('function');
});
});
});