import { test, expect, afterEach, vi } from "vitest" import { Runtime } from "../src/runtime" const FILE = "app/views/test.html.erb" const PAGE = `` + `` + `` + `` + `` + `` let runtime: Runtime | null = null afterEach(() => { runtime?.stop() runtime = null document.body.innerHTML = "" }) test("an empty fragment shows its fallback immediately even with a delay", async () => { document.body.innerHTML = PAGE const transport = vi.fn(() => new Promise(() => {})) runtime = Runtime.start({ state: { refetchTransport: transport as never, refetchDebounce: 0 } }) runtime.state.setState({ album: "b" }) await vi.waitFor(() => { if (!document.getElementById("waiting")) { throw new Error("fallback not shown yet") } }, { timeout: 200 }) expect(document.getElementById("waiting")!.textContent).toBe("loading") })