UNPKG

one

Version:

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

78 lines 2.47 kB
var import_core = require("@react-navigation/core"); var import_vitest = require("vitest"); var import_router = require("./router.cjs"); 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: import_vitest.vi.fn(), dispatch: import_vitest.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))); } (0, import_vitest.describe)("linkTo against a tree that went away", () => { let errorSpy; let ref; (0, import_vitest.beforeEach)(() => { globalThis["__vxrnHeadless"] = true; errorSpy = import_vitest.vi.spyOn(console, "error").mockImplementation(() => {}); ref = (0, import_core.createNavigationContainerRef)(); ref.current = mountedNavigator(); (0, import_router.initialize)(createMockContext({ "./_layout.tsx": { default: () => null }, "./index.tsx": { default: () => null }, "./other.tsx": { default: () => null } }), ref, new URL("http://one.test/")); }); (0, import_vitest.afterEach)(() => { errorSpy.mockRestore(); delete globalThis["__vxrnHeadless"]; }); (0, import_vitest.it)("abandons a navigation whose navigator detached during the preload", async () => { const navigation = (0, import_router.replace)("/other"); ref.current = null; await navigation; (0, import_vitest.expect)(notInitializedCalls(errorSpy)).toEqual([]); }); (0, import_vitest.it)("stops the post-dispatch route poll once the navigator detaches", async () => { await (0, import_router.replace)("/other"); ref.current = null; await new Promise(resolve => setTimeout(resolve, 80)); (0, import_vitest.expect)(notInitializedCalls(errorSpy)).toEqual([]); }); });