Skip to content

Commit 71064e6

Browse files
committed
🤖 fix: lint errors in test file
Change-Id: I5344ad935e5d333b34c9e1e471e528fc86f82ca7 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent b271187 commit 71064e6

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

src/browser/hooks/useAvailableScripts.test.ts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
1-
import { GlobalWindow } from "happy-dom";
2-
3-
const win = new GlobalWindow();
4-
// @ts-expect-error -- Patching global for test environment
5-
global.window = win;
6-
// @ts-expect-error -- Patching global for test environment
7-
global.document = win.document;
8-
// @ts-expect-error -- Patching global for test environment
9-
global.navigator = win.navigator;
10-
11-
import { describe, it, expect, beforeEach, afterEach, mock, type Mock } from "bun:test";
1+
import { describe, it, expect, beforeEach, afterEach, mock, type Mock, beforeAll, afterAll } from "bun:test";
122
import { renderHook, waitFor } from "@testing-library/react";
133
import { useAvailableScripts } from "./useAvailableScripts";
4+
import { GlobalWindow } from "happy-dom";
145

156
// Define types for our mock
167
type ListScriptsMock = Mock<() => Promise<{ success: boolean; data?: unknown[]; error?: string }>>;
178

189
describe("useAvailableScripts", () => {
1910
const mockListScripts = mock() as unknown as ListScriptsMock;
11+
let originalWindow: unknown;
12+
let originalDocument: unknown;
13+
let originalNavigator: unknown;
14+
15+
beforeAll(() => {
16+
// Save originals
17+
originalWindow = global.window;
18+
originalDocument = global.document;
19+
originalNavigator = global.navigator;
20+
21+
// Setup happy-dom
22+
const win = new GlobalWindow();
23+
// @ts-expect-error -- Patching global for test environment
24+
global.window = win;
25+
// @ts-expect-error -- Patching global for test environment
26+
global.document = win.document;
27+
// @ts-expect-error -- Patching global for test environment
28+
global.navigator = win.navigator;
29+
});
30+
31+
afterAll(() => {
32+
// Restore originals
33+
// @ts-expect-error -- Restoring globals
34+
global.window = originalWindow;
35+
// @ts-expect-error -- Restoring globals
36+
global.document = originalDocument;
37+
// @ts-expect-error -- Restoring globals
38+
global.navigator = originalNavigator;
39+
});
2040

2141
beforeEach(() => {
2242
// Mock window.api attached to the global window
@@ -31,7 +51,10 @@ describe("useAvailableScripts", () => {
3151
afterEach(() => {
3252
mock.restore();
3353
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
34-
delete (global.window as any).api;
54+
if (global.window) {
55+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
56+
delete (global.window as any).api;
57+
}
3558
});
3659

3760
it("should fetch and return executable scripts", async () => {

0 commit comments

Comments
 (0)