// A page whose rail sits in its flow must not be ready before the rail: the rail would then appear a // moment after the page and shove its content sideways. import { describe, expect, it } from "vitest"; import type { ComponentType } from "react"; import { lazyWithPreload, lazyWithPreloadAlongside } from "./lazyWithPreload"; const component = (() => null) as ComponentType; describe("lazyWithPreloadAlongside", () => { it("is ready only once its rail has loaded too", async () => { let releaseRail = () => {}; const rail = lazyWithPreload( () => new Promise<{ default: ComponentType }>((resolve) => { releaseRail = () => resolve({ default: component }); }), ); const page = lazyWithPreloadAlongside(async () => ({ default: component }), rail); let pageReady = false; const loading = page.preload().then(() => { pageReady = true; }); await new Promise((r) => setTimeout(r, 0)); expect(pageReady).toBe(false); // its own code is in, its rail's is not releaseRail(); await loading; expect(pageReady).toBe(true); }); });