diff options
Diffstat (limited to 'vitest-setup.ts')
| -rw-r--r-- | vitest-setup.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vitest-setup.ts b/vitest-setup.ts index 143ac96..94aa5e8 100644 --- a/vitest-setup.ts +++ b/vitest-setup.ts @@ -14,3 +14,43 @@ if (typeof globalThis.ResizeObserver === "undefined") { disconnect(): void {} }; } +// jsdom implements no Element.animate (Web Animations API — svelte transitions +// and the grid's FLIP reflow use it); stub a no-op so components render in tests. +if (typeof Element !== "undefined" && typeof Element.prototype.animate !== "function") { + Element.prototype.animate = () => { + const noop = () => {}; + return { + cancel: noop, + finish: noop, + pause: noop, + play: noop, + onfinish: null, + } as unknown as Animation; + }; +} +// jsdom implements no PointerEvent constructor — testing-library's +// fireEvent.pointerDown falls back to a plain Event and drops the pointer +// properties (clientX/pointerType/…). Polyfill over jsdom's MouseEvent (the +// drag/press logic is pointer-driven; a real browser always has PointerEvent). +if (typeof globalThis.PointerEvent === "undefined") { + class PointerEventPolyfill extends MouseEvent { + readonly pointerType: string; + constructor(type: string, init: PointerEventInit = {}) { + super(type, init); + this.pointerType = init.pointerType ?? ""; + } + } + globalThis.PointerEvent = PointerEventPolyfill as unknown as typeof PointerEvent; +} + +// jsdom has no native modal dialog lifecycle. Fake only this browser edge; +// real-browser checks cover top-layer rendering and native focus containment. +if (typeof HTMLDialogElement !== "undefined" && !HTMLDialogElement.prototype.showModal) { + HTMLDialogElement.prototype.showModal = function () { + this.open = true; + this.querySelector<HTMLElement>("button")?.focus(); + }; + HTMLDialogElement.prototype.close = function () { + this.open = false; + }; +} |
