Skip to content

Commit 6243e32

Browse files
committed
Refactor terminal state store tests for improved modularity and clarity
- Update test setup to use dynamic imports for selectThreadTerminalState and useTerminalStateStore. - Enhance localStorage stubbing with vi.stubGlobal for cleaner state management. - Maintain existing test functionality while improving code organization.
1 parent 1e56f43 commit 6243e32

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

apps/web/src/terminalStateStore.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { ThreadId } from "@okcode/contracts";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
33

4-
import { selectThreadTerminalState, useTerminalStateStore } from "./terminalStateStore";
5-
64
const THREAD_ID = ThreadId.makeUnsafe("thread-1");
75

6+
let selectThreadTerminalState: typeof import("./terminalStateStore").selectThreadTerminalState;
7+
let useTerminalStateStore: typeof import("./terminalStateStore").useTerminalStateStore;
8+
89
describe("terminalStateStore actions", () => {
9-
beforeEach(() => {
10-
const storage = {
10+
beforeEach(async () => {
11+
vi.resetModules();
12+
vi.stubGlobal("localStorage", {
1113
getItem: () => null,
1214
setItem: () => {},
1315
removeItem: () => {},
1416
clear: () => {},
15-
};
17+
});
1618

17-
vi.stubGlobal("localStorage", storage);
19+
({ selectThreadTerminalState, useTerminalStateStore } = await import("./terminalStateStore"));
1820
localStorage.clear();
1921
useTerminalStateStore.setState({ terminalStateByThreadId: {} });
2022
});

0 commit comments

Comments
 (0)