Skip to content

Commit

Permalink
Modify fetch.js tests to check for headers being cloned rather than s…
Browse files Browse the repository at this point in the history
…haring them between clones
  • Loading branch information
zerotri committed Dec 2, 2024
1 parent b72a2f0 commit f4d1982
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/integration/fetch/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ export const handler = serveTest(async (t) => {
body: 'te',
method: 'post'
});

request.headers.set("foo", "bar")
const newRequest = request.clone();

strictEqual(newRequest instanceof Request, true, 'newRequest instanceof Request');
strictEqual(newRequest.method, request.method, 'newRequest.method');
strictEqual(newRequest.url, request.url, 'newRequest.url');
deepStrictEqual([...newRequest.headers], [...request.headers], 'newRequest.headers');
strictEqual(request.bodyUsed, false, 'request.bodyUsed');
strictEqual(newRequest.bodyUsed, false, 'newRequest.bodyUsed');
strictEqual(newRequest.body instanceof ReadableStream, true, 'newRequest.body instanceof ReadableStream');

strictEqual(newRequest.headers.get("foo"), "bar", 'newRequest.status pre-modification');
request.headers.set("foo", "bao")
strictEqual(newRequest.headers.get("foo"), "bar", 'newRequest.status post-modification');
strictEqual(request.headers.get("foo"), "bao", 'request.status post-modification');
}

{
Expand Down Expand Up @@ -68,14 +76,21 @@ export const handler = serveTest(async (t) => {
status: 200,
statusText: 'Success'
});
response.headers.set("foo", "bar")
const newResponse = response.clone();

strictEqual(newResponse instanceof Response, true, 'newResponse instanceof Request');
strictEqual(response.bodyUsed, false, 'response.bodyUsed');
strictEqual(newResponse.bodyUsed, false, 'newResponse.bodyUsed');
deepStrictEqual([...newResponse.headers], [...response.headers], 'newResponse.headers');
strictEqual(newResponse.status, 200, 'newResponse.status');
strictEqual(newResponse.statusText, 'Success', 'newResponse.statusText');
strictEqual(newResponse.body instanceof ReadableStream, true, 'newResponse.body instanceof ReadableStream');

strictEqual(newResponse.headers.get("foo"), "bar", 'newResponse.status pre-modification');
response.headers.set("foo", "bao")
strictEqual(newResponse.headers.get("foo"), "bar", 'newResponse.status post-modification');
strictEqual(response.headers.get("foo"), "bao", 'response.status post-modification');
}

{
Expand Down

0 comments on commit f4d1982

Please sign in to comment.