Files
cfw-autumn/server/tests/unit/utils/hash-json.test.ts

17 lines
518 B
TypeScript

import { describe, expect, test } from "bun:test";
import { hashJson } from "@/utils/hash/hashJson.js";
describe("hashJson", () => {
test("returns a stable 64 character hex digest independent of object key order", () => {
const first = hashJson({
value: { beta: 2, alpha: { z: true, a: null }, skipped: undefined },
});
const second = hashJson({
value: { skipped: undefined, alpha: { a: null, z: true }, beta: 2 },
});
expect(first).toMatch(/^[a-f0-9]{64}$/);
expect(second).toBe(first);
});
});