-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.ts
104 lines (88 loc) · 2.34 KB
/
test.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { tests, describe, addAssertion, it } from './src/index';
import delay from 'delay';
addAssertion(actual => {
const even = actual % 2 === 0;
return {
ok: even,
actual: even ? `even` : `odd`,
expected: `even`,
};
}, `isEven`);
tests(async () => {
describe(`tests`, it => {
it(`should add the numbers`, expect => {
expect(1 + 2).toBe(3);
});
it(`should subtract the numbers`, expect => {
expect(1 - 2).not.toBe(0);
});
});
describe(`add() should work`, it => {
it(`should add the numbers`, expect => {
expect(1 + 2).toBe(3);
});
it(`should subtract the numbers and not be 0`, expect => {
expect(1 - 2).not.toBe(0);
});
it(`should be even`, expect => {
expect(4).custom(`isEven`);
});
it(`should parse multiline into yml`, expect => {
expect(`thing\nother\nthree`).toBe(`thing\nother\nthree`);
});
});
describe(`toBeTruthy`, it => {
it(`should have a toBeTruthy method`, expect => {
expect(3).toBeTruthy();
});
it(`should have a not.toBeTruthy method`, expect => {
expect(0).not.toBeTruthy();
});
});
await describe(`try things async`, async it => {
await it(`should still run async`, async expect => {
await delay(500);
expect(2).not.toBe(0);
});
it(`should still run async 2`, expect => {
expect(2).not.toBe(0);
});
});
await delay(400);
await describe(`try things even more async`, async it => {
await delay(400);
it(`should pass`, expect => {
expect(4).custom(`isEven`);
});
});
describe(`test out the other methods`, it => {
it(`should match regex`, expect => {
expect('Elijah').toMatch(/Eli/);
});
it(`should match object`, expect => {
expect({ a: 'b', c: { d: ['e'], f: 'g' } }).toMatchObject({
a: 'b',
c: { d: ['e'], f: 'g' },
});
expect({ a: 'b', c: { d: ['e'], f: 'g' } }).not.toMatchObject({
a: 'b',
c: { d: ['e'], f: 'd' },
});
expect([`this`, `that`, `then`]).toMatchObject([`this`, `that`, `then`]);
});
it(`should throw an error`, expect => {
expect(() => {
throw new Error(`hello!`);
}).toThrow(/hello/);
});
it(`should have the right types`, expect => {
expect('me').toBeType('string');
expect({}).toBeType('object');
expect(true).toBeType('boolean');
});
});
it(`should server it's purpose`, expect => {
expect(undefined).toBe(undefined);
expect(undefined).toBe(undefined);
});
});