fix: Task2 质量修复(TS2774/降级分支测试/跨平台checksize/显式lib)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-15 11:39:34 +08:00
parent 15853f20b3
commit cda80b1605
4 changed files with 13 additions and 3 deletions
+8 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";
import { uuid } from "../src/util";
describe("uuid", () => {
it("生成 36 位且不重复", () => {
@@ -6,4 +6,11 @@ describe("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();
});
});