@@ -118,6 +118,18 @@ describe("graphql()", () => {
118
118
} ,
119
119
} ;
120
120
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
+
121
133
const RepositoryDocument = new TypedDocumentString <
122
134
{
123
135
repository : { issues : { edges : Array < { node : { title : string } } > } } ;
@@ -142,17 +154,7 @@ describe("graphql()", () => {
142
154
authorization : `token secret123` ,
143
155
} ,
144
156
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 ,
156
158
} ,
157
159
} ) . then ( ( result ) => {
158
160
expect ( JSON . stringify ( result ) ) . toStrictEqual ( JSON . stringify ( mockData ) ) ;
@@ -220,28 +222,28 @@ describe("graphql()", () => {
220
222
}
221
223
}` ) ;
222
224
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
+
223
239
return graphql ( query , {
224
240
headers : {
225
241
authorization : `token secret123` ,
226
242
} ,
227
243
owner : "octokit" ,
228
244
repo : "graphql.js" ,
229
245
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 ,
245
247
} ,
246
248
} ) ;
247
249
} ) ;
0 commit comments