Files
fangke/sdk/test/util.test.ts
T

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();
});
});