Update test

This commit is contained in:
Jarred Sumner
2022-12-02 19:35:28 -08:00
parent 43f2a8eb85
commit 4e6b905a98
2 changed files with 35 additions and 27 deletions

View File

@@ -31,7 +31,7 @@ describe("Headers", () => {
"Set-Cookie": "foo=bar; Path=/; HttpOnly",
});
expect(headers.count).toBe(5);
expect(headers.getSetCookie()).toEqual(["foo=bar; Path=/; HttpOnly"]);
expect(headers.getAll("set-cookie")).toEqual(["foo=bar; Path=/; HttpOnly"]);
});
it(".getSetCookie() with array", () => {
@@ -44,7 +44,7 @@ describe("Headers", () => {
["Set-Cookie", "foo2=bar2; Path=/; HttpOnly"],
]);
expect(headers.count).toBe(6);
expect(headers.getSetCookie()).toEqual([
expect(headers.getAll("set-cookie")).toEqual([
"foo=bar; Path=/; HttpOnly",
"foo2=bar2; Path=/; HttpOnly",
]);

View File

@@ -599,31 +599,6 @@ it("should support reloading", async () => {
server.stop();
});
it("should support multiple Set-Cookie headers", async () => {
const server = serve({
port: port++,
fetch(req) {
return new Response("hello", {
headers: [
["Another-Header", "1"],
["Set-Cookie", "foo=bar"],
["Set-Cookie", "baz=qux"],
],
});
},
});
const response = await fetch(`http://${server.hostname}:${server.port}`);
server.stop();
expect(response.headers.getAll("Set-Cookie")).toEqual(["foo=bar", "baz=qux"]);
expect(response.headers.getSetCookie()).toEqual(["foo=bar", "baz=qux"]);
const cloned = response.clone().headers;
expect(cloned.getAll("Set-Cookie")).toEqual(["foo=bar", "baz=qux"]);
expect(cloned.getSetCookie()).toEqual(["foo=bar", "baz=qux"]);
});
describe("status code text", () => {
const fixture = {
200: "OK",
@@ -703,3 +678,36 @@ describe("status code text", () => {
});
}
});
it("should support multiple Set-Cookie headers", async () => {
const server = serve({
port: port++,
fetch(req) {
return new Response("hello", {
headers: [
["Another-Header", "1"],
["Set-Cookie", "foo=bar"],
["Set-Cookie", "baz=qux"],
],
});
},
});
const response = await fetch(`http://${server.hostname}:${server.port}`);
server.stop();
expect(response.headers.getAll("Set-Cookie")).toEqual(["foo=bar", "baz=qux"]);
expect(response.headers.get("Set-Cookie")).toEqual("foo=bar, baz=qux");
const cloned = response.clone().headers;
expect(response.headers.getAll("Set-Cookie")).toEqual(["foo=bar", "baz=qux"]);
response.headers.delete("Set-Cookie");
expect(response.headers.getAll("Set-Cookie")).toEqual([]);
response.headers.delete("Set-Cookie");
expect(cloned.getAll("Set-Cookie")).toEqual(["foo=bar", "baz=qux"]);
expect(new Headers(cloned).getAll("Set-Cookie")).toEqual([
"foo=bar",
"baz=qux",
]);
});