-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupTests.ts
More file actions
26 lines (23 loc) · 909 Bytes
/
setupTests.ts
File metadata and controls
26 lines (23 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import "@testing-library/jest-dom/vitest";
import { vi } from "vitest";
import failOnConsole from "vitest-fail-on-console";
failOnConsole();
// Mock scrollIntoView which is not available in jsdom
// Only mock if Element is defined (jsdom environment)
if (typeof Element !== "undefined") {
Element.prototype.scrollIntoView = vi.fn();
}
// Mock HTMLDialogElement methods not implemented in jsdom.
// showModal sets the open attribute; close removes it and dispatches the close
// event so that components listening to the native close event work in tests.
if (typeof HTMLDialogElement !== "undefined") {
HTMLDialogElement.prototype.showModal = vi.fn(function (
this: HTMLDialogElement,
) {
this.setAttribute("open", "");
});
HTMLDialogElement.prototype.close = vi.fn(function (this: HTMLDialogElement) {
this.removeAttribute("open");
this.dispatchEvent(new Event("close"));
});
}