UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

62 lines (61 loc) 1.79 kB
import { beforeEach, expect, test, vi } from "vitest"; import { useInitializeOneRouter } from "./useInitializeOneRouter.mjs"; const probe = vi.hoisted(() => ({ navigationRef: { current: null }, routerNavigationRef: null, initialize: vi.fn((_context, navigationRef) => { probe.routerNavigationRef = navigationRef; }) })); vi.hoisted(() => { Object.defineProperty(globalThis, "window", { configurable: true, value: {} }); }); vi.mock("@react-navigation/core", () => ({ useNavigationContainerRef: () => probe.navigationRef })); vi.mock("../useLoader", () => ({ resetLoaderState: vi.fn() })); vi.mock("./router", () => ({ initialize: probe.initialize, get navigationRef() { return probe.routerNavigationRef; }, routeNode: null, rootComponent: null, initialState: void 0 })); vi.mock("./linkingConfig", () => ({ ensureBaseLinkingConfig: vi.fn(), getSSRInitialState: vi.fn() })); beforeEach(() => { probe.initialize.mockClear(); }); test("initializes a fresh navigation root with its current location", () => { const context = Object.assign(function routeContext(_id) { throw new Error("route context is not evaluated by this probe"); }, { keys: () => [], resolve: id => id, id: "preview-lifecycle-probe" }); const firstRef = { current: null }; probe.navigationRef = firstRef; useInitializeOneRouter(context, new URL("https://preview.test/")); const nextRef = { current: null }; const nextLocation = new URL("https://preview.test/home/feed"); probe.navigationRef = nextRef; useInitializeOneRouter(context, nextLocation); expect(probe.initialize).toHaveBeenLastCalledWith(context, nextRef, nextLocation, void 0); }); //# sourceMappingURL=useInitializeOneRouter.preview-lifecycle.test.mjs.map