-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.spec.js
More file actions
93 lines (75 loc) · 2.21 KB
/
Copy pathApp.spec.js
File metadata and controls
93 lines (75 loc) · 2.21 KB
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
import { render, waitFor } from '@testing-library/react';
import { createElement as e } from 'react';
import { App } from './App';
import { Provider } from 'react-redux';
import { combineReducers, createStore } from 'redux';
import { foo, bar } from './reducer';
// TODO: https://jestjs.io/docs/expect#expectextendmatchers
// TODO: https://jestjs.io/docs/timer-mocks
// Intellisense for typescript requires explicit import.
// https://jestjs.io/docs/expect#tobevalue
// These are not extended.
// console.log({ describe, expect });
expect.extend({
toThouShallPass(actual) {
if (typeof actual !== 'boolean') {
throw new Error('toThouShallPass expects a boolean');
}
return {
pass: actual,
message: () => `Thou shall ${actual ? '' : 'not '}pass!`,
};
},
toGetMoar(...args) {
// console.log({ args: JSON.stringify(args) });
return {
pass: true,
message: () => `I got moar!`,
};
},
});
// Extended here!
// console.log({ expect });
describe('', () => {
it('should run waitFor many times', async () => {
render(
e(Provider, { store: createStore(combineReducers({ foo, bar })) }, e(App))
); // Do I even need to render?
let count = 0;
await expect(
waitFor(
() => {
// screen.debug()
++count;
throw new Error('rerun the waitFor callback');
},
{ timeout: 1000 }
)
).rejects.toThrow();
// Allow us to see the count once the test passes.
// console.log(`waitFor ran ${count} times`);
});
it('should prove why i can await expect.rejects()', () => {
return expect(
new Promise((_, reject) => {
reject(new Error('lol'));
})
).rejects.toThrow('lol');
});
it('should also prove why i can await expect.rejects()', async () => {
await expect(
new Promise((_, reject) => {
reject(new Error('lol'));
})
).rejects.toThrow('lol');
});
it('should perform on thou shall pass!', () => {
expect(true).toThouShallPass();
expect(false).not.toThouShallPass();
});
it('should pass a lot of stuff to get moar!', () => {
expect({ a: true, b: 'hello' }).toGetMoar('first', 'second', {
third: [1, 2],
});
});
});