openclaw/src/infra/outbound/abort.test.ts
2026-03-13 20:03:09 +00:00

22 lines
668 B
TypeScript

import { describe, expect, it } from "vitest";
import { throwIfAborted } from "./abort.js";
describe("throwIfAborted", () => {
it("does nothing when the signal is missing or not aborted", () => {
expect(() => throwIfAborted()).not.toThrow();
expect(() => throwIfAborted(new AbortController().signal)).not.toThrow();
});
it("throws a standard AbortError when the signal is aborted", () => {
const controller = new AbortController();
controller.abort();
expect(() => throwIfAborted(controller.signal)).toThrowError(
expect.objectContaining({
name: "AbortError",
message: "Operation aborted",
}),
);
});
});