one
Version:
One is a new React Framework that makes Vite serve both native and web.
104 lines (103 loc) • 2.76 kB
JavaScript
import { createNavigationContainerRef } from "@react-navigation/core";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { initialize, replace } from "./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: vi.fn(),
dispatch: 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);
});
});
}
describe("linkTo against a tree that went away", function () {
var errorSpy;
var ref;
beforeEach(function () {
globalThis["__vxrnHeadless"] = true;
errorSpy = vi.spyOn(console, "error").mockImplementation(function () {});
ref = createNavigationContainerRef();
ref.current = mountedNavigator();
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/"));
});
afterEach(function () {
errorSpy.mockRestore();
delete globalThis["__vxrnHeadless"];
});
it("abandons a navigation whose navigator detached during the preload", async function () {
var navigation = replace("/other");
ref.current = null;
await navigation;
expect(notInitializedCalls(errorSpy)).toEqual([]);
});
it("stops the post-dispatch route poll once the navigator detaches", async function () {
await replace("/other");
ref.current = null;
await new Promise(function (resolve) {
return setTimeout(resolve, 80);
});
expect(notInitializedCalls(errorSpy)).toEqual([]);
});
});
//# sourceMappingURL=linkToOrphaned.test.native.js.map