Skip to content

Commit

Permalink
fix(router): update jest testing-library mocks (#899)
Browse files Browse the repository at this point in the history
backport of expo/expo#25110
  • Loading branch information
marklawlor authored Nov 7, 2023
1 parent dee2e60 commit 6a60601
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/expo-router/src/testing-library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
10 changes: 6 additions & 4 deletions packages/expo-router/src/testing-library/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> } = {
value: "",
};
let mockInitialUrl: string | Promise<string> = "";

export function setInitialUrl(value: string) {
mockInitialUrl = value;
}

jest.mock("expo-linking", () => {
const module: typeof import("expo-linking") = {
Expand All @@ -31,7 +33,7 @@ jest.mock("expo-linking", () => {
return { remove() {} } as any;
},
async getInitialURL() {
return initialUrlRef.value;
return mockInitialUrl;
},
};

Expand Down

0 comments on commit 6a60601

Please sign in to comment.