Initial Commit
This commit is contained in:
55
packages/media/image/emblem-solver/src/errors/errors.test.ts
Normal file
55
packages/media/image/emblem-solver/src/errors/errors.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { EMBLEM_SOLVER_CODES, EmblemSolverError } from "./errors.js";
|
||||
import * as barrel from "./index.js";
|
||||
|
||||
describe("EMBLEM_SOLVER_CODES", () => {
|
||||
it("exposes all three codes", { timeout: 5000 }, () => {
|
||||
expect(EMBLEM_SOLVER_CODES.INVALID_GRID).toBe(
|
||||
"EMBLEM_SOLVER.INVALID_GRID"
|
||||
);
|
||||
expect(EMBLEM_SOLVER_CODES.INVALID_OPTIONS).toBe(
|
||||
"EMBLEM_SOLVER.INVALID_OPTIONS"
|
||||
);
|
||||
expect(EMBLEM_SOLVER_CODES.INVALID_PIXEL).toBe(
|
||||
"EMBLEM_SOLVER.INVALID_PIXEL"
|
||||
);
|
||||
expect(Object.isFrozen(EMBLEM_SOLVER_CODES)).toBe(true);
|
||||
expect(Object.keys(EMBLEM_SOLVER_CODES).sort()).toEqual([
|
||||
"INVALID_GRID",
|
||||
"INVALID_OPTIONS",
|
||||
"INVALID_PIXEL",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("EmblemSolverError", () => {
|
||||
it("preserves code and cause", { timeout: 5000 }, () => {
|
||||
const inner = new Error("inner");
|
||||
const err = new EmblemSolverError(
|
||||
EMBLEM_SOLVER_CODES.INVALID_GRID,
|
||||
"emblem.grid.invalid",
|
||||
{ cause: inner }
|
||||
);
|
||||
expect(err).toBeInstanceOf(EmblemSolverError);
|
||||
expect(err).toBeInstanceOf(Error);
|
||||
expect(err.code).toBe("EMBLEM_SOLVER.INVALID_GRID");
|
||||
expect(err.cause).toBe(inner);
|
||||
expect(err.name).toBe("EmblemSolverError");
|
||||
});
|
||||
|
||||
it("can be thrown with each code", { timeout: 5000 }, () => {
|
||||
for (const code of Object.values(EMBLEM_SOLVER_CODES)) {
|
||||
const err = new EmblemSolverError(code, `key.${code}`);
|
||||
expect(err.code).toBe(code);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors barrel", () => {
|
||||
it("errors subpath barrel re-exports the public surface", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
expect(barrel.EmblemSolverError).toBe(EmblemSolverError);
|
||||
expect(barrel.EMBLEM_SOLVER_CODES).toBe(EMBLEM_SOLVER_CODES);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user