UNPKG

one

Version:

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

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