-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
48 lines (38 loc) · 1.67 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
import { setupServer, request } from "./setupServer";
const server = setupServer([]);
beforeAll(() => server.listen());
/**
* @note Jest doesn't support `afterEach` in concurrent mode.
* But you don't need that because "server.boundary()" encapsulates
* the request handler changes within that function's scope.
*/
test.concurrent("uses initial handlers", server.boundary(async () => {
expect(await request("GET", "/one")).toEqual(null);
expect(await request("GET", "/two")).toEqual(null);
}));
test.concurrent("adds two overrides", server.boundary(async () => {
server.use(["GET", "/two", 202], ["GET", "/three", 3]);
expect(await request("GET", "/one")).toEqual(null);
expect(await request("GET", "/two")).toEqual(202);
expect(await request("GET", "/three")).toEqual(3);
}));
test.concurrent("adds one override", server.boundary(async () => {
server.use(["GET", "/two", 2]);
expect(await request("GET", "/two")).toEqual(2);
expect(await request("POST", "/one")).toEqual(null);
}));
test.concurrent("uses initial handlers after reset", server.boundary(async () => {
expect(await request("GET", "/one?a=1")).toEqual(null);
expect(await request("GET", "/two")).toEqual(null);
}));
test.concurrent("adds in-test overrides", server.boundary(async () => {
expect(await request("GET", "/two")).toEqual(null);
server.use(["GET", "/two", 123]);
expect(await request("GET", "/two")).toEqual(123);
server.use(["GET", "/three", 333]);
expect(await request("GET", "/two")).toEqual(123);
expect(await request("GET", "/three")).toEqual(333);
server.reset();
expect(await request("GET", "/two")).toEqual(null);
expect(await request("GET", "/three")).toEqual(null);
}));