mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 23:51:48 +00:00
perf(test): use microtask wait in fetch rejection test
This commit is contained in:
@@ -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<void> {
|
||||
await new Promise<void>((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();
|
||||
|
||||
Reference in New Issue
Block a user