Skip to content

Commit

Permalink
updates tests to use the new v12 fetch-mock apis
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfloyd committed Nov 13, 2024
1 parent 4b5c978 commit 97fd257
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions test/integration/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,34 @@ describe("Smoke tests", () => {

it("userAgent option", () => {
const mock = fetchMock
.sandbox()
.getOnce("https://api.github.com/", (_url, { headers }) => {
.createInstance()
.getOnce("https://api.github.com/", (_url) => {
// @ts-ignore headers has wrong typing in fetch-mock 8.3.2
expect(headers["user-agent"]).toMatch(/^my-app\/1.2.3 /);
expect(
mock.callHistory.calls()[0].options.headers!["user-agent"],
).toMatch(/^my-app\/1.2.3 /);
// expect(headers["user-agent"]).toMatch(/^my-app\/1.2.3 /);

return { ok: true };
});

const octokit = new Octokit({
userAgent: "my-app/1.2.3",
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});
return octokit.request("/");
});

it("@octokit/plugin-rest-endpoint-methods", () => {
const mock = fetchMock
.sandbox()
.createInstance()
.getOnce("path:/repos/octocat/hello-world", { ok: true });

const octokit = new Octokit({
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

Expand All @@ -58,7 +61,7 @@ describe("Smoke tests", () => {

it("@octokit/plugin-request-log", () => {
const mock = fetchMock
.sandbox()
.createInstance()
.getOnce("path:/", { status: 200, body: {} })
.getOnce("path:/", { status: 404, body: {} }, { overwriteRoutes: false });

Expand All @@ -72,7 +75,7 @@ describe("Smoke tests", () => {
const octokit = new Octokit({
log: consoleStub,
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

Expand Down
4 changes: 2 additions & 2 deletions test/issues/881-redirect-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("https://github.com/octokit/rest.js/issues/881", () => {
"https://issue-881-codeload.github.com/octocat/Hello-World/legacy.tar.gz/master";

const mock = fetchMock
.sandbox()
.createInstance()
.headOnce(
"https://api.github.com/repos/octocat/Hello-World/tarball/master",
{
Expand All @@ -20,7 +20,7 @@ describe("https://github.com/octokit/rest.js/issues/881", () => {

const octokit = new Octokit({
request: {
fetch: mock,
fetch: mock.fetchHandler,
},
});

Expand Down

0 comments on commit 97fd257

Please sign in to comment.