test(ui): make sidebar context test flush synchronously

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-06-16 10:02:03 +00:00
1 parent dc5bca7a46
commit 6072eade58
1 file changed
+5 -1
+5 -1
View File
@@ -1,6 +1,6 @@
// @vitest-environment jsdom
import { act } from "react";
import { flushSync } from "react-dom";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { SidebarProvider, useSidebar } from "./SidebarContext";
@@ -13,6 +13,10 @@ const COLLAPSED_STORAGE_KEY = "paperclip.sidebar.collapsed";
// Mutable media state driving the matchMedia mock.
const mediaState = { mobile: false, hoverFine: true };
function act(callback: () => void) {
flushSync(callback);
}
function setViewport({ mobile, hoverFine }: { mobile?: boolean; hoverFine?: boolean }) {
if (typeof mobile === "boolean") mediaState.mobile = mobile;
if (typeof hoverFine === "boolean") mediaState.hoverFine = hoverFine;