Skip to content

Commit 7fc28e2

Browse files
authored
Add test for response constructor with body and status (#4641)
<!--- Thank you for contributing to Boa! Please fill out the template below, and remove or add any information as you feel necessary. ---> This Pull Request fixes/closes #4547 . Summary :- The `Response` constructor was a dummy implementation that completely ignored its `body` and `options` parameters, always creating an empty response with status 200. The constructor now properly parses the `body` argument, reads `status` and `headers` from the options object, validates the status code and returns `JsResult<Self>` to handle errors . Also added the "hello world" test mentioned in the issue for testing.
1 parent cc7b25b commit 7fc28e2

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

core/runtime/src/fetch/tests/response.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,26 @@ fn response_clone_preserves_status() {
464464
}),
465465
]);
466466
}
467+
468+
#[test]
469+
fn response_constructor_with_body_and_status() {
470+
run_test_actions([
471+
TestAction::harness(),
472+
TestAction::inspect_context(|ctx| register(&[], ctx)),
473+
TestAction::run(
474+
r#"
475+
globalThis.response = (async () => {
476+
const response = new Response('Hello World', { status: 404 });
477+
assertEq(response.status, 404);
478+
assertEq(response.type, "default");
479+
const text = await response.text();
480+
assertEq(text, "Hello World");
481+
})();
482+
"#,
483+
),
484+
TestAction::inspect_context(|ctx| {
485+
let response = ctx.global_object().get(js_str!("response"), ctx).unwrap();
486+
response.as_promise().unwrap().await_blocking(ctx).unwrap();
487+
}),
488+
]);
489+
}

0 commit comments

Comments
 (0)