Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions test/fetch/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ testParams.forEach((params) => {

it('AbortController works (POST with string body)', async () => {
const controller = new FetchAbortController();
setTimeout(() => controller.abort(), 1);
const { signal } = controller;
controller.abort();

const method = 'POST';
const body = 'Hello, World!';
Expand All @@ -326,8 +326,8 @@ testParams.forEach((params) => {

it('built-in AbortController works (POST with string body)', async () => {
const controller = new AbortController();
setTimeout(() => controller.abort(), 1);
const { signal } = controller;
controller.abort();

const method = 'POST';
const body = 'Hello, World!';
Expand All @@ -336,10 +336,21 @@ testParams.forEach((params) => {
await fetch(`${server.origin}/inspect`, { signal, method, body });
assert.fail();
} catch (err) {
if (!(err instanceof AbortError)) {
// eslint-disable-next-line no-console
console.error(err);
}
assert(err instanceof AbortError);
}
});

it('built-in AbortController works (abort during fetch)', async () => {
const controller = new AbortController();
const { signal } = controller;

const fetchPromise = fetch(`${server.origin}/status/200?delay=5000`, { signal });
setTimeout(() => controller.abort(), 50);

try {
await fetchPromise;
assert.fail();
} catch (err) {
assert(err instanceof AbortError);
}
});
Expand Down
Loading