Skip to content

Commit

Permalink
fix: [capricorn86#1718] Fetch aborted due to timeout signal error mes…
Browse files Browse the repository at this point in the history
…sage name incorrect
  • Loading branch information
btea committed Feb 17, 2025
1 parent 2f709e4 commit 6f14913
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/happy-dom/src/fetch/Fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export default class Fetch {
if (this.request.signal.aborted) {
throw new this.#window.DOMException(
'The operation was aborted.',
this.request.signal.reason.name ||
DOMExceptionNameEnum.abortError
);
}
Expand Down
13 changes: 12 additions & 1 deletion packages/happy-dom/test/fetch/AbortSignal.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Event from '../../src/event/Event.js';
import { describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import * as PropertySymbol from '../../src/PropertySymbol.js';
import BrowserWindow from '../../src/window/BrowserWindow.js';
import Window from '../../src/window/Window.js';
Expand Down Expand Up @@ -63,6 +63,17 @@ describe('AbortSignal', () => {
expect(signal.reason).toBeInstanceOf(DOMException);
expect(signal.reason?.name).toBe('TimeoutError');
});

it('After Abortsignal timeout, sending a request with the wrong name still being "TimeoutError" ', async () => {
try {
const signal = AbortSignal.timeout(20)
const now = Date.now()
await vi.waitUntil(() => Date.now() - now > 100)
await fetch('https://example.com', { signal })
} catch (e) {
expect((e as Error).name).toStrictEqual('TimeoutError')
}
})
});

describe('AbortSignal.any()', () => {
Expand Down

0 comments on commit 6f14913

Please sign in to comment.