Skip to content

Commit c73e182

Browse files
authored
wpt: add test (nodejs#1836)
1 parent 84ae57e commit c73e182

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

lib/fetch/body.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,7 @@ function bodyMixinMethods (instance) {
357357
defParamCharset: 'utf8'
358358
})
359359
} catch (err) {
360-
// Error due to headers:
361-
throw Object.assign(new TypeError(), { cause: err })
360+
throw new DOMException(`${err}`, 'AbortError')
362361
}
363362

364363
busboy.on('field', (name, value) => {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Changing the body after it have been passed to Response/Request
2+
// should not change the outcome of the consumed body
3+
4+
const url = 'http://a';
5+
const method = 'post';
6+
7+
promise_test(async t => {
8+
const body = new FormData();
9+
body.set('a', '1');
10+
const res = new Response(body);
11+
const req = new Request(url, { method, body });
12+
body.set('a', '2');
13+
assert_true((await res.formData()).get('a') === '1');
14+
assert_true((await req.formData()).get('a') === '1');
15+
}, 'FormData is cloned');
16+
17+
promise_test(async t => {
18+
const body = new URLSearchParams({a: '1'});
19+
const res = new Response(body);
20+
const req = new Request(url, { method, body });
21+
body.set('a', '2');
22+
assert_true((await res.formData()).get('a') === '1');
23+
assert_true((await req.formData()).get('a') === '1');
24+
}, 'URLSearchParams is cloned');
25+
26+
promise_test(async t => {
27+
const body = new Uint8Array([97]); // a
28+
const res = new Response(body);
29+
const req = new Request(url, { method, body });
30+
body[0] = 98; // b
31+
assert_true(await res.text() === 'a');
32+
assert_true(await req.text() === 'a');
33+
}, 'TypedArray is cloned');
34+
35+
promise_test(async t => {
36+
const body = new Uint8Array([97]); // a
37+
const res = new Response(body.buffer);
38+
const req = new Request(url, { method, body: body.buffer });
39+
body[0] = 98; // b
40+
assert_true(await res.text() === 'a');
41+
assert_true(await req.text() === 'a');
42+
}, 'ArrayBuffer is cloned');
43+
44+
promise_test(async t => {
45+
const body = new Blob(['a']);
46+
const res = new Response(body);
47+
const req = new Request(url, { method, body });
48+
assert_true(await res.blob() !== body);
49+
assert_true(await req.blob() !== body);
50+
}, 'Blob is cloned');

0 commit comments

Comments
 (0)