forked from martinfrancois/question-driven-talk-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-vitest.ts
More file actions
23 lines (19 loc) · 799 Bytes
/
Copy pathsetup-vitest.ts
File metadata and controls
23 lines (19 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { afterAll, beforeAll, vi } from "vitest";
vi.mock("zustand"); // to make it work like Jest (auto-mocking)
// Mocks the textarea's scrollHeight to a fixed value to ensure consistent height calculations
// across different test environments and runs to make snapshot tests deterministic.
beforeAll(() => {
Object.defineProperty(HTMLTextAreaElement.prototype, "scrollHeight", {
get() {
return 20; // Set a consistent height value
},
configurable: true,
});
});
// Makes all properties non-readonly and optional, so they can be deleted from the object
type Deletable<T> = { -readonly [P in keyof T]?: T[P] };
afterAll(() => {
// Remove the mock to prevent side effects
delete (HTMLTextAreaElement.prototype as Deletable<HTMLTextAreaElement>)
.scrollHeight;
});