UNPKG

one

Version:

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

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