diff --git a/src/infra/fetch.test.ts b/src/infra/fetch.test.ts index 3da1399944f..c9dc1c7a4dc 100644 --- a/src/infra/fetch.test.ts +++ b/src/infra/fetch.test.ts @@ -2,6 +2,10 @@ import { describe, expect, it, vi } from "vitest"; import { withFetchPreconnect } from "../test-utils/fetch-mock.js"; import { resolveFetch, wrapFetchWithAbortSignal } from "./fetch.js"; +async function waitForMicrotaskTurn(): Promise { + await new Promise((resolve) => queueMicrotask(resolve)); +} + function createForeignSignalHarness() { let abortHandler: (() => void) | null = null; const removeEventListener = vi.fn((event: string, handler: () => void) => { @@ -86,7 +90,7 @@ describe("wrapFetchWithAbortSignal", () => { try { await expect(wrapped("https://example.com", { signal: fakeSignal })).rejects.toBe(fetchError); await Promise.resolve(); - await new Promise((resolve) => setTimeout(resolve, 0)); + await waitForMicrotaskTurn(); expect(unhandled).toEqual([]); expect(removeEventListener).toHaveBeenCalledOnce();