Files
Jyotisha/frontend/tests/birth-time-user-errors.test.ts
2026-07-22 09:43:11 +08:00

28 lines
1.2 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { birthTimeUserError } from "../src/lib/birth-time-user-error.ts";
test("birth-time errors never expose browser implementation messages", () => {
assert.equal(
birthTimeUserError(new DOMException("The string did not match the expected pattern.")),
"候选时间暂时无法保存,请检查网络后重试。",
);
});
test("birth-time errors preserve a safe server message", () => {
assert.equal(birthTimeUserError(new Error("候选结果已变化")), "候选结果已变化");
});
test("all guided and automatic journey mutations normalize implementation errors", () => {
const sources = [
"../src/hooks/use-birth-time-guided-journey.ts",
"../src/hooks/use-birth-time-automatic-journey-effects.ts",
].map((path) => readFileSync(new URL(path, import.meta.url), "utf8"));
for (const source of sources) {
assert.ok((source.match(/setError\(birthTimeUserError\(caught\)\)/g) ?? []).length >= 1);
assert.equal(source.includes("setError(caught.message"), false);
assert.equal(source.includes("setError(caught instanceof Error ? caught.message"), false);
}
});