Skip to content

Commit 2764dcd

Browse files
chore(deps): update dependency fetch-mock to v12 (#606)
* chore(deps): update dependency fetch-mock to v12 * updates tests to use the new v12 fetch-mock apis --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nick Floyd <[email protected]>
1 parent 86bebd1 commit 2764dcd

File tree

6 files changed

+188
-156
lines changed

6 files changed

+188
-156
lines changed

package-lock.json

Lines changed: 23 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@types/jest": "^29.0.0",
3535
"@types/node": "^22.0.0",
3636
"esbuild": "^0.24.0",
37-
"fetch-mock": "^11.0.0",
37+
"fetch-mock": "^12.0.0",
3838
"glob": "^11.0.0",
3939
"jest": "^29.0.0",
4040
"prettier": "3.4.2",

test/defaults.test.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ describe("graphql.defaults()", () => {
3636
},
3737
};
3838

39+
const mock = fetchMock.createInstance().post(
40+
"https://api.github.com/graphql",
41+
{ data: mockData },
42+
{
43+
headers: {
44+
authorization: "token secret123",
45+
},
46+
},
47+
);
48+
3949
const authenticatedGraphql = graphql.defaults({
4050
headers: {
4151
authorization: `token secret123`,
4252
},
4353
request: {
44-
fetch: fetchMock.sandbox().post(
45-
"https://api.github.com/graphql",
46-
{ data: mockData },
47-
{
48-
headers: {
49-
authorization: "token secret123",
50-
},
51-
},
52-
),
54+
fetch: mock.fetchHandler,
5355
},
5456
});
5557
return authenticatedGraphql(`{
@@ -92,20 +94,22 @@ describe("graphql.defaults()", () => {
9294
},
9395
};
9496

97+
const mock = fetchMock.createInstance().post(
98+
"https://github.acme-inc.com/api/graphql",
99+
{ data: mockData },
100+
{
101+
headers: {
102+
authorization: "token secret123",
103+
},
104+
},
105+
);
106+
95107
const authenticatedGraphql = graphql.defaults({
96108
headers: {
97109
authorization: `token secret123`,
98110
},
99111
request: {
100-
fetch: fetchMock.sandbox().post(
101-
"https://github.acme-inc.com/api/graphql",
102-
{ data: mockData },
103-
{
104-
headers: {
105-
authorization: "token secret123",
106-
},
107-
},
108-
),
112+
fetch: mock.fetchHandler,
109113
},
110114
});
111115
const acmeGraphql = authenticatedGraphql.defaults({
@@ -127,21 +131,23 @@ describe("graphql.defaults()", () => {
127131
});
128132

129133
it("handle baseUrl set with /api/v3 suffix", () => {
134+
const mock = fetchMock.createInstance().post(
135+
"https://github.acme-inc.com/api/graphql",
136+
{ data: { ok: true } },
137+
{
138+
headers: {
139+
authorization: "token secret123",
140+
},
141+
},
142+
);
143+
130144
const ghesGraphQl = graphql.defaults({
131145
baseUrl: "https://github.acme-inc.com/api/v3",
132146
headers: {
133147
authorization: `token secret123`,
134148
},
135149
request: {
136-
fetch: fetchMock.sandbox().post(
137-
"https://github.acme-inc.com/api/graphql",
138-
{ data: { ok: true } },
139-
{
140-
headers: {
141-
authorization: "token secret123",
142-
},
143-
},
144-
),
150+
fetch: mock.fetchHandler,
145151
},
146152
});
147153

@@ -182,7 +188,7 @@ describe("graphql.defaults()", () => {
182188
authorization: `token secret123`,
183189
},
184190
request: {
185-
fetch: fetchMock.sandbox().post(
191+
fetch: fetchMock.createInstance().post(
186192
"https://github.acme-inc.com/api/graphql",
187193
{ data: mockData },
188194
{

test/error.test.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ describe("errors", () => {
2424
],
2525
};
2626

27+
const mock = fetchMock
28+
.createInstance()
29+
.post("https://api.github.com/graphql", mockResponse);
30+
2731
return graphql(query, {
2832
headers: {
2933
authorization: `token secret123`,
3034
},
3135
request: {
32-
fetch: fetchMock
33-
.sandbox()
34-
.post("https://api.github.com/graphql", mockResponse),
36+
fetch: mock.fetchHandler,
3537
},
3638
})
3739
.then(() => {
@@ -72,14 +74,16 @@ describe("errors", () => {
7274
],
7375
};
7476

77+
const mock = fetchMock
78+
.createInstance()
79+
.post("https://api.github.com/graphql", mockResponse);
80+
7581
return graphql(query, {
7682
headers: {
7783
authorization: `token secret123`,
7884
},
7985
request: {
80-
fetch: fetchMock
81-
.sandbox()
82-
.post("https://api.github.com/graphql", mockResponse),
86+
fetch: mock.fetchHandler,
8387
},
8488
})
8589
.then(() => {
@@ -131,17 +135,21 @@ describe("errors", () => {
131135
],
132136
};
133137

138+
const mock = fetchMock
139+
.createInstance()
140+
.post("https://api.github.com/graphql", {
141+
body: mockResponse,
142+
headers: {
143+
"x-github-request-id": "C5E6:259A:1351B40:2E88B87:5F1F9C41",
144+
},
145+
});
146+
134147
return graphql(query, {
135148
headers: {
136149
authorization: `token secret123`,
137150
},
138151
request: {
139-
fetch: fetchMock.sandbox().post("https://api.github.com/graphql", {
140-
body: mockResponse,
141-
headers: {
142-
"x-github-request-id": "C5E6:259A:1351B40:2E88B87:5F1F9C41",
143-
},
144-
}),
152+
fetch: mock.fetchHandler,
145153
},
146154
})
147155
.then(() => {
@@ -173,12 +181,16 @@ describe("errors", () => {
173181
}
174182
}`;
175183

184+
const mock = fetchMock
185+
.createInstance()
186+
.post("https://api.github.com/graphql", 500);
187+
176188
return graphql(query, {
177189
headers: {
178190
authorization: `token secret123`,
179191
},
180192
request: {
181-
fetch: fetchMock.sandbox().post("https://api.github.com/graphql", 500),
193+
fetch: mock.fetchHandler,
182194
},
183195
})
184196
.then(() => {

0 commit comments

Comments
 (0)