UNPKG

one

Version:

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

80 lines (79 loc) 2.33 kB
import { createNavigationContainerRef } from "@react-navigation/core"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { initialize, replace } from "./router.mjs"; function createMockContext(files) { const keys = Object.keys(files); const ctx = function (id) { return files[id] || {}; }; ctx.keys = () => keys; ctx.resolve = id => id; ctx.id = "link-to-orphaned"; return ctx; } function mountedNavigator() { return { isReady: () => true, getRootState: () => ({ key: "stack-1", type: "stack", index: 0, routeNames: ["index", "other"], routes: [{ key: "index-1", name: "index" }], stale: false }), getCurrentRoute: () => ({ key: "index-1", name: "index" }), resetRoot: vi.fn(), dispatch: vi.fn(), addListener: () => () => {}, removeListener: () => {} }; } const NOT_INITIALIZED = "hasn't been initialized yet"; function notInitializedCalls(spy) { return spy.mock.calls.filter(call => call.some(arg => typeof arg === "string" && arg.includes(NOT_INITIALIZED))); } describe("linkTo against a tree that went away", () => { let errorSpy; let ref; beforeEach(() => { globalThis["__vxrnHeadless"] = true; errorSpy = vi.spyOn(console, "error").mockImplementation(() => {}); ref = createNavigationContainerRef(); ref.current = mountedNavigator(); initialize(createMockContext({ "./_layout.tsx": { default: () => null }, "./index.tsx": { default: () => null }, "./other.tsx": { default: () => null } }), ref, new URL("http://one.test/")); }); afterEach(() => { errorSpy.mockRestore(); delete globalThis["__vxrnHeadless"]; }); it("abandons a navigation whose navigator detached during the preload", async () => { const navigation = replace("/other"); ref.current = null; await navigation; expect(notInitializedCalls(errorSpy)).toEqual([]); }); it("stops the post-dispatch route poll once the navigator detaches", async () => { await replace("/other"); ref.current = null; await new Promise(resolve => setTimeout(resolve, 80)); expect(notInitializedCalls(errorSpy)).toEqual([]); }); }); //# sourceMappingURL=linkToOrphaned.test.mjs.map