-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
apollo_test_raw_app_test
76 lines (63 loc) · 1.86 KB
/
apollo_test_raw_app_test
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
/* File: tests/integration.test.js */
import { testApiHandler } from 'next-test-api-route-handler';
// Import the handler under test from the app/api directory
import * as appHandler from '../app/api/graphql/route';
describe('my-test (app router)', () => {
it('does what I want 1', async () => {
expect.hasAssertions();
await testApiHandler({
appHandler,
test: async ({ fetch }) => {
const query = `query { hello }`;
const res = await fetch({
method: 'POST',
headers: {
'content-type': 'application/json' // Must use correct content type
},
body: JSON.stringify({ query })
});
await expect(res.json()).resolves.toStrictEqual({
data: { hello: 'world' }
});
}
});
});
it('does what I want 2', async () => {
expect.hasAssertions();
await testApiHandler({
appHandler,
test: async ({ fetch }) => {
const query = `query { hello }`;
const res = await fetch({
method: 'POST',
headers: {
'content-type': 'application/json' // Must use correct content type
},
body: JSON.stringify({ query })
});
await expect(res.json()).resolves.toStrictEqual({
data: { hello: 'world' }
});
}
});
});
it('does what I want 3', async () => {
expect.hasAssertions();
await testApiHandler({
appHandler,
test: async ({ fetch }) => {
const query = `query { hello }`;
const res = await fetch({
method: 'POST',
headers: {
'content-type': 'application/json' // Must use correct content type
},
body: JSON.stringify({ query })
});
await expect(res.json()).resolves.toStrictEqual({
data: { hello: 'world' }
});
}
});
});
});