Răsfoiți Sursa

chore: bump coverage

Sv443 3 săptămâni în urmă
părinte
comite
e16dc9dd2c
3 a modificat fișierele cu 22 adăugiri și 4 ștergeri
  1. 1 1
      lib/math.spec.ts
  2. 14 1
      lib/misc.spec.ts
  3. 7 2
      lib/translation.spec.ts

+ 1 - 1
lib/math.spec.ts

@@ -4,7 +4,7 @@ import { bitSetHas, clamp, digitCount, mapRange, randRange, roundFixed } from ".
 //#region clamp
 describe("math/clamp", () => {
   it("Clamps a value between min and max", () => {
-    expect(clamp(5, 0, 10)).toBe(5);
+    expect(clamp(5, 10)).toBe(5);
     expect(clamp(-5, 0, 10)).toBe(0);
     expect(clamp(15, 0, 10)).toBe(10);
     expect(clamp(Number.MAX_SAFE_INTEGER, 0, Infinity)).toBe(Number.MAX_SAFE_INTEGER);

+ 14 - 1
lib/misc.spec.ts

@@ -1,5 +1,6 @@
 import { describe, expect, it } from "vitest";
 import { autoPlural, consumeGen, consumeStringGen, fetchAdvanced, getListLength, insertValues, pauseFor, purifyObj } from "./misc.js";
+import { randomId } from "./crypto.js";
 
 //#region autoPlural
 describe("misc/autoPlural", () => {
@@ -71,6 +72,15 @@ describe("misc/fetchAdvanced", () => {
       expect(e).toBeUndefined();
     }
   });
+
+  it("Throws error on invalid resource", async () => {
+    try {
+      const res = await fetchAdvanced("invalid-url");
+    }
+    catch(e) {
+      expect(e).toBeInstanceOf(Error);
+    }
+  });
 });
 
 //#region consumeGen
@@ -94,6 +104,7 @@ describe("misc/consumeStringGen", () => {
     expect(await consumeStringGen("a")).toBe("a");
     expect(await consumeStringGen(() => "b")).toBe("b");
     expect(await consumeStringGen(() => Promise.resolve("c"))).toBe("c");
+    expect(await consumeStringGen({ toString: () => "d" })).toBe("d");
   });
 });
 
@@ -112,7 +123,9 @@ describe("misc/getListLength", () => {
     expect(getListLength({ count: 3 })).toBe(3);
 
     // @ts-expect-error
-    expect(getListLength({})).toThrow(TypeError);
+    expect(getListLength({}, true)).toBe(0);
+    // @ts-expect-error
+    expect(getListLength({}, false)).toBe(NaN);
   });
 });
 

+ 7 - 2
lib/translation.spec.ts

@@ -25,8 +25,9 @@ describe("Translation", () => {
     expect(tr.for("de", "hello")).toBe("Hallo");
     expect(tr.for("de", "goodbye")).toBe("Goodbye");
 
-    tr.deleteTranslations("de");
+    expect(tr.deleteTranslations("de")).toBe(true);
     expect(tr.for("de", "hello")).toBe("Hello");
+    expect(tr.deleteTranslations("de")).toBe(false);
 
     tr.setFallbackLanguage();
     expect(tr.for("de", "hello")).toBe("hello");
@@ -60,7 +61,11 @@ describe("Translation", () => {
     expect(tr.for("en", "templateLiteral", { name: "Jeff" })).toBe("Hello, Jeff");
     expect(tr.for("en", "templateLiteral", { toString: () => "Jeff" })).toBe("Hello, Jeff");
 
-    tr.deleteTransform(tr.transforms.percent[0]);
+    expect(tr.deleteTransform(tr.transforms.percent[0])).toBe(true);
     expect(tr.for("en", "percent", "Jeff")).toBe("Hello, %1");
+    expect(tr.deleteTransform(tr.transforms.percent[0])).toBe(false);
+
+    tr.deleteTransform(tr.transforms.templateLiteral[1]);
+    expect(tr.for("en", "templateLiteral", "Jeff")).toBe("Hello, ${name}");
   });
 });