This commit is contained in:
Andrew Pimenov 2026-10-07 06:55:56 +03:00 • committed by GitHub
commit b64bbe571f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,8 +1,9 @@
import { describe, it, expect, beforeAll } from "vitest"; import { describe, it, expect, beforeAll, vi } from "vitest";
import { SumEngine } from "./index"; import { SumEngine } from "./index";
import { qty, EvalError, XRefError } from "./types"; import { qty, EvalError, XRefError } from "./types";
import type { XRefResolution, EvalCtx } from "./evaluator"; import type { XRefResolution, EvalCtx } from "./evaluator";
import { evaluate } from "./evaluator"; import { evaluate } from "./evaluator";
import * as evaluator from "./evaluator";
import { formatValue } from "./formatter"; import { formatValue } from "./formatter";
let eng: SumEngine; let eng: SumEngine;
@ -451,4 +452,17 @@ describe("evaluation errors", () => {
} as unknown as EvalCtx; } as unknown as EvalCtx;
expect(() => evaluate({ k: "xref", sheet: "Sheet", key: "key" }, ctx)).toThrowError(XRefError); expect(() => evaluate({ k: "xref", sheet: "Sheet", key: "key" }, ctx)).toThrowError(XRefError);
}); });
it("catches and handles arbitrary errors in evaluateDocument", () => {
// Spy on evaluator.evaluate and force an arbitrary error
const spy = vi.spyOn(evaluator, "evaluate").mockImplementation(() => {
throw new Error("Forced execution anomaly");
});
const results = eng.evaluateDocument("1 + 1");
expect(results).toHaveLength(1);
expect(results[0].error).toBe("Forced execution anomaly");
spy.mockRestore();
});
}); });