Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(vitest-pool-workers): test intercepting fetch with different query pattern #7682

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions fixtures/vitest-pool-workers-examples/misc/test/fetch-mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,30 @@ it("falls through to global fetch() if unmatched", async () => {
it("intercepts URLs with query parameters with repeated keys", async () => {
fetchMock
.get("https://example.com")
.intercept({ path: "/foo/bar?a=1&a=2" })
.reply(200, "body");
.intercept({ path: "/foo", query: { key: "value" } })
.reply(200, "foo");

let response = await fetch("https://example.com/foo/bar?a=1&a=2");
expect(response.url).toEqual("https://example.com/foo/bar?a=1&a=2");
expect(await response.text()).toBe("body");
fetchMock
.get("https://example.com")
.intercept({ path: "/bar?a=1&a=2" })
.reply(200, "bar");

fetchMock
.get("https://example.com")
.intercept({ path: "/baz", query: { key1: ["a", "b"], key2: "c" } })
.reply(200, "baz");

let response1 = await fetch("https://example.com/foo?key=value");
expect(response1.url).toEqual("https://example.com/foo?key=value");
expect(await response1.text()).toBe("foo");

let response2 = await fetch("https://example.com/bar?a=1&a=2");
expect(response2.url).toEqual("https://example.com/bar?a=1&a=2");
expect(await response2.text()).toBe("bar");

let response3 = await fetch("https://example.com/baz?key1=a&key2=c&key1=b");
expect(response3.url).toEqual("https://example.com/baz?key1=a&key2=c&key1=b");
expect(await response3.text()).toBe("baz");
});

describe("AbortSignal", () => {
Expand Down
Loading