mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 00:26:26 +00:00
24 lines
868 B
TypeScript
24 lines
868 B
TypeScript
import { afterEach, describe, expect, test } from "bun:test";
|
|||
|
|
import { apiFetch } from "../src/helpers";
|
||
|
|
|
||
|
|
// A stalled upstream connection (accepted socket, no response) would otherwise
|
||
|
|
// hang the CLI forever - fetch has no default timeout. Assert every request
|
||
|
|
// carries an AbortSignal timeout. This fails on the pre-fix code (no signal).
|
||
|
|
const originalFetch = globalThis.fetch;
|
||
|
|
afterEach(() => {
|
||
|
|
globalThis.fetch = originalFetch;
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("apiFetch request timeout", () => {
|
||
|
|
test("passes an AbortSignal timeout to fetch", async () => {
|
||
|
|
let init: RequestInit | undefined;
|
||
|
|
globalThis.fetch = (async (_url: string | URL | Request, i?: RequestInit) => {
|
||
|
|
init = i;
|
||
|
|
return new Response("{}", { status: 200 });
|
||
|
|
}) as unknown as typeof fetch;
|
||
|
|
|
||
|
|
await apiFetch("/search");
|
||
|
|
expect(init?.signal).toBeInstanceOf(AbortSignal);
|
||
|
|
});
|
||
|
|
});
|