Skip to content

Commit

Permalink
fix: ensure that mocked fetch responses have a valid URL property (#6362
Browse files Browse the repository at this point in the history
)
  • Loading branch information
petebacondarwin authored Jul 29, 2024
1 parent 585cec0 commit 35289e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/proud-chefs-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/vitest-pool-workers": patch
---

fix: ensure that mocked fetch responses have a valid URL property

Fixes [#6350](https://github.com/cloudflare/workers-sdk/issues/6350)
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ it("falls through to global fetch() if unmatched", async () => {
.reply(200, "body");

let response = await fetch("https://example.com");
expect(response.url).toEqual("https://example.com/");
expect(await response.text()).toBe("body");

response = await fetch("https://example.com/bad");
expect(response.url).toEqual("https://example.com/bad");
expect(await response.text()).toBe("fallthrough:GET https://example.com/bad");
});
1 change: 1 addition & 0 deletions packages/vitest-pool-workers/src/worker/fetch-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ globalThis.fetch = async (input, init) => {
statusText: responseStatusText,
headers: responseHeaders,
});
Object.defineProperty(response, "url", { value: url.href });
responseResolve(response);
} else {
responseResolve(maybeResponse);
Expand Down

0 comments on commit 35289e3

Please sign in to comment.