Files
SnapOtter/tests/unit/web/with-timeout.test.ts
SnapOtterandGitHub 23efce9df0 fix(analytics): harden analytics opt-out and feedback surfaces (#423)
Server stops phoning Sentry home after opt-out (release-health sessions + client reports off); settings saves diff-send only changed keys so a stale tab cannot revert an instance-wide opt-out; disabling analytics hides the feedback UI immediately; optIn resumes PostHog after re-enable; onboarding survey writes time out at 15s; inline tool-feedback prompt arms a shown-cooldown.
2026-07-04 14:02:28 +08:00

27 lines
816 B
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { withTimeout } from "@/lib/with-timeout";
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
describe("withTimeout", () => {
it("resolves with the promise value when it settles before the deadline", async () => {
await expect(withTimeout(Promise.resolve("ok"), 1000)).resolves.toBe("ok");
});
it("rejects when the promise is still pending past the deadline", async () => {
const neverSettles = new Promise<string>(() => {});
const settled = withTimeout(neverSettles, 1000).then(
() => "resolved",
(err: Error) => `rejected:${err.message}`,
);
await vi.advanceTimersByTimeAsync(1000);
expect(await settled).toMatch(/rejected:.*timed out/i);
});
});