Ver Fonte

fix: unit tests & file names

Sv443 há 1 semana atrás
pai
commit
92103c3758
5 ficheiros alterados com 23 adições e 4 exclusões
  1. 19 0
      lib/Errors.spec.ts
  2. 0 0
      lib/Errors.ts
  3. 1 1
      lib/dom.spec.ts
  4. 2 2
      lib/dom.ts
  5. 1 1
      lib/index.ts

+ 19 - 0
lib/Errors.spec.ts

@@ -0,0 +1,19 @@
+
+import { describe, expect, it } from "vitest";
+import { PlatformError } from "./errors.js";
+
+describe("Errors", () => {
+  it("All class instances have the date property", () => {
+    const classes = [
+      ["PlatformError", PlatformError],
+    ] as const;
+
+    for(const [name, Cls] of classes) {
+      const instance = new Cls(`Test ${name}`);
+      expect(instance).toBeInstanceOf(Cls);
+      expect(instance.date).toBeInstanceOf(Date);
+      expect(instance.message).toBe(`Test ${name}`);
+      expect(instance.name).toBe(name);
+    }
+  });
+});

+ 0 - 0
lib/error.ts → lib/Errors.ts


+ 1 - 1
lib/dom.spec.ts

@@ -1,6 +1,6 @@
 import { describe, expect, it } from "vitest";
 import { addGlobalStyle, addParent, getSiblingsFrame, getUnsafeWindow, interceptWindowEvent, isDomLoaded, observeElementProp, onDomLoad, openInNewTab, preloadImages, probeElementStyle, setInnerHtmlUnsafe } from "./dom.js";
-import { PlatformError } from "./errors.js";
+import { PlatformError } from "./Errors.js";
 
 //#region getUnsafeWindow
 describe("dom/getUnsafeWindow", () => {

+ 2 - 2
lib/dom.ts

@@ -3,7 +3,7 @@
  * This module contains various functions for working with the DOM - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#dom)
  */
 
-import { PlatformError } from "./errors.js";
+import { PlatformError } from "./Errors.js";
 
 //#region unsafeWindow
 
@@ -134,7 +134,7 @@ export function interceptEvent<
 ): void {
   // @ts-ignore
   if(typeof window.GM === "object" && GM?.info?.scriptHandler && GM.info.scriptHandler === "FireMonkey" && (eventObject === window || eventObject === getUnsafeWindow()))
-    throw new PlatformError("Intercepting window events is not supported on FireMonkey due to the isolated context the userscript runs in.");
+    throw new PlatformError("Intercepting window events is not supported on FireMonkey due to the isolated context the userscript is forced to run in.");
 
   // default is 25 on FF so this should hopefully be more than enough
   // @ts-ignore

+ 1 - 1
lib/index.ts

@@ -5,7 +5,7 @@
 
 export * from "./Dialog.js";
 export * from "./dom.js";
-export * from "./error.js";
+export * from "./Errors.js";
 export * from "./Mixins.js";
 export * from "./SelectorObserver.js";
 export * from "@sv443-network/coreutils";