mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-21 20:24:42 +00:00
test: add test case for fetch throwing TypeError on network errors
This commit is contained in:
@@ -203,3 +203,15 @@
|
||||
testing.expectEqual(true, response.body !== null);
|
||||
});
|
||||
</script>
|
||||
|
||||
<script id=error>
|
||||
testing.async(async (restore) => {
|
||||
try {
|
||||
await fetch('http://198.51.100.1:0');
|
||||
testing.expectTrue(false); // force failure
|
||||
} catch (err) {
|
||||
restore();
|
||||
testing.expectTrue(err instanceof TypeError)
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -193,9 +193,7 @@ fn httpErrorCallback(ctx: *anyopaque, err: anyerror) void {
|
||||
defer ls.deinit();
|
||||
|
||||
// fetch() must reject with a TypeError on network errors per spec
|
||||
const err_handle = ls.local.isolate.createTypeError("Failed to fetch");
|
||||
const err_val = js.Value{ .local = ls.local, .handle = err_handle };
|
||||
ls.toLocal(self._resolver).reject("fetch error", err_val);
|
||||
ls.toLocal(self._resolver).rejectError("fetch error", .{ .type_error = @errorName(err) });
|
||||
}
|
||||
|
||||
fn httpShutdownCallback(ctx: *anyopaque) void {
|
||||
|
||||
Reference in New Issue
Block a user