diff --git a/packages/expo-router/src/testing-library/index.tsx b/packages/expo-router/src/testing-library/index.tsx index 15d9f180..b045acea 100644 --- a/packages/expo-router/src/testing-library/index.tsx +++ b/packages/expo-router/src/testing-library/index.tsx @@ -15,7 +15,7 @@ import { requireContext, requireContextWithOverrides, } from "./context-stubs"; -import { initialUrlRef } from "./mocks"; +import { setInitialUrl } from "./mocks"; // re-export everything export * from "@testing-library/react-native"; @@ -60,7 +60,8 @@ export function renderRouter( let ctx: RequireContext; // Reset the initial URL - initialUrlRef.value = initialUrl as any; + + setInitialUrl(initialUrl); // Force the render to be synchronous process.env.EXPO_ROUTER_IMPORT_MODE_WEB = "sync"; diff --git a/packages/expo-router/src/testing-library/mocks.ts b/packages/expo-router/src/testing-library/mocks.ts index ce0461e9..0771feaa 100644 --- a/packages/expo-router/src/testing-library/mocks.ts +++ b/packages/expo-router/src/testing-library/mocks.ts @@ -14,9 +14,11 @@ jest.mock("react-native-reanimated", () => { // Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper"); -export const initialUrlRef: { value: string | Promise } = { - value: "", -}; +let mockInitialUrl: string | Promise = ""; + +export function setInitialUrl(value: string) { + mockInitialUrl = value; +} jest.mock("expo-linking", () => { const module: typeof import("expo-linking") = { @@ -31,7 +33,7 @@ jest.mock("expo-linking", () => { return { remove() {} } as any; }, async getInitialURL() { - return initialUrlRef.value; + return mockInitialUrl; }, };