Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

rootNavigation.test.ts

31 lines1.0 KB

1import { expect, it, vi } from "vite-plus/test";
2import type { NavigationContainerRef } from "@react-navigation/native";
3​
4vi.mock("@react-navigation/native", () => ({
5 createNavigationContainerRef: () => ({
6 current: null as { isReady(): boolean } | null,
7 isReady() {
8 return this.current?.isReady() ?? false;
9 },
10 }),
11}));
12​
13const { attachRootNavigation, rootNavigationRef } = await import("./rootNavigation");
14​
15function fakeContainer() {
16 return { isReady: () => true } as NavigationContainerRef<ReactNavigation.RootParamList>;
18​
19it("keeps the newer container when an older root unmounts after it attached", () => {
20 // Android activity replacement mounts the new root before the old one unmounts.
21 const detachPrevious = attachRootNavigation(fakeContainer());
22 const current = fakeContainer();
23 const detachCurrent = attachRootNavigation(current);
24​
25 detachPrevious();
26 expect(rootNavigationRef.current).toBe(current);
27 expect(rootNavigationRef.isReady()).toBe(true);
28​
29 detachCurrent();
30 expect(rootNavigationRef.current).toBeNull();
31});