Skip to content

Commit 77edf5e

Browse files
committed
Align tests with new mock style
1 parent 19ab295 commit 77edf5e

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

test/graphql.test.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ describe("graphql()", () => {
118118
},
119119
};
120120

121+
const mock = fetchMock.createInstance().post(
122+
"https://api.github.com/graphql",
123+
{ data: mockData },
124+
{
125+
headers: {
126+
accept: "application/vnd.github.v3+json",
127+
authorization: "token secret123",
128+
"user-agent": userAgent,
129+
},
130+
},
131+
);
132+
121133
const RepositoryDocument = new TypedDocumentString<
122134
{
123135
repository: { issues: { edges: Array<{ node: { title: string } }> } };
@@ -142,17 +154,7 @@ describe("graphql()", () => {
142154
authorization: `token secret123`,
143155
},
144156
request: {
145-
fetch: fetchMock.sandbox().post(
146-
"https://api.github.com/graphql",
147-
{ data: mockData },
148-
{
149-
headers: {
150-
accept: "application/vnd.github.v3+json",
151-
authorization: "token secret123",
152-
"user-agent": userAgent,
153-
},
154-
},
155-
),
157+
fetch: mock.fetchHandler,
156158
},
157159
}).then((result) => {
158160
expect(JSON.stringify(result)).toStrictEqual(JSON.stringify(mockData));
@@ -220,28 +222,28 @@ describe("graphql()", () => {
220222
}
221223
}`);
222224

225+
const mock = fetchMock
226+
.createInstance()
227+
.post("https://api.github.com/graphql", (callHistory) => {
228+
//@ts-ignore mock.fetchHandler is not typed
229+
const body = JSON.parse(mock.callHistory.calls()[0].options.body);
230+
expect(body.query).toEqual(query.toString());
231+
expect(body.variables).toStrictEqual({
232+
owner: "octokit",
233+
repo: "graphql.js",
234+
});
235+
236+
return { data: {} };
237+
});
238+
223239
return graphql(query, {
224240
headers: {
225241
authorization: `token secret123`,
226242
},
227243
owner: "octokit",
228244
repo: "graphql.js",
229245
request: {
230-
fetch: fetchMock
231-
.sandbox()
232-
.post(
233-
"https://api.github.com/graphql",
234-
(_url, options: OctokitTypes.RequestOptions) => {
235-
const body = JSON.parse(options.body);
236-
expect(body.query).toEqual(query.toString());
237-
expect(body.variables).toStrictEqual({
238-
owner: "octokit",
239-
repo: "graphql.js",
240-
});
241-
242-
return { data: {} };
243-
},
244-
),
246+
fetch: mock.fetchHandler,
245247
},
246248
});
247249
});

0 commit comments

Comments
 (0)