2026-09-15 11:39:34 +08:00
|
|
|
import { describe, it, expect, vi } from "vitest";
|
2026-09-15 11:30:42 +08:00
|
|
|
import { uuid } from "../src/util";
|
|
|
|
|
describe("uuid", () => {
|
|
|
|
|
it("生成 36 位且不重复", () => {
|
|
|
|
|
const a = uuid(), b = uuid();
|
|
|
|
|
expect(a).toMatch(/^[0-9a-f-]{36}$/);
|
|
|
|
|
expect(a).not.toBe(b);
|
|
|
|
|
});
|
2026-09-15 11:39:34 +08:00
|
|
|
it("Math.random 降级分支:格式正确且唯一", () => {
|
|
|
|
|
vi.stubGlobal("crypto", {});
|
|
|
|
|
const a = uuid(), b = uuid();
|
|
|
|
|
expect(a).toMatch(/^[0-9a-f-]{36}$/);
|
|
|
|
|
expect(a).not.toBe(b);
|
|
|
|
|
vi.unstubAllGlobals();
|
|
|
|
|
});
|
2026-09-15 11:30:42 +08:00
|
|
|
});
|