cda80b1605
Co-Authored-By: Claude Code <noreply@anthropic.com>
17 lines
501 B
TypeScript
17 lines
501 B
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
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);
|
|
});
|
|
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();
|
|
});
|
|
});
|