Skip to content

Commit

Permalink
Merge pull request #51530 from Anaslancer/storybook-run-without-error
Browse files Browse the repository at this point in the history
Storybook run without error
  • Loading branch information
yuwenmemon authored Oct 28, 2024
2 parents f92f184 + 06eab28 commit da2e668
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions __mocks__/@react-navigation/native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const {triggerTransitionEnd, addListener} = isJestEnv
addListener: () => {},
};

const realOrMockedUseNavigation = isJestEnv ? realReactNavigation.useNavigation : {};
const useNavigation = () => ({
...realReactNavigation.useNavigation,
navigate: jest.fn(),
...realOrMockedUseNavigation,
navigate: isJestEnv ? jest.fn() : () => {},
getState: () => ({
routes: [],
}),
Expand All @@ -30,17 +31,20 @@ type NativeNavigationMock = typeof ReactNavigation & {
};

export * from '@react-navigation/core';
const Link = realReactNavigation.Link;
const LinkingContext = realReactNavigation.LinkingContext;
const NavigationContainer = realReactNavigation.NavigationContainer;
const ServerContainer = realReactNavigation.ServerContainer;
const DarkTheme = realReactNavigation.DarkTheme;
const DefaultTheme = realReactNavigation.DefaultTheme;
const ThemeProvider = realReactNavigation.ThemeProvider;
const useLinkBuilder = realReactNavigation.useLinkBuilder;
const useLinkProps = realReactNavigation.useLinkProps;
const useLinkTo = realReactNavigation.useLinkTo;
const useScrollToTop = realReactNavigation.useScrollToTop;
const Link = isJestEnv ? realReactNavigation.Link : () => null;
const LinkingContext = isJestEnv ? realReactNavigation.LinkingContext : () => null;
const NavigationContainer = isJestEnv ? realReactNavigation.NavigationContainer : () => null;
const ServerContainer = isJestEnv ? realReactNavigation.ServerContainer : () => null;
const DarkTheme = isJestEnv ? realReactNavigation.DarkTheme : {};
const DefaultTheme = isJestEnv ? realReactNavigation.DefaultTheme : {};
const ThemeProvider = isJestEnv ? realReactNavigation.ThemeProvider : () => null;
const useLinkBuilder = isJestEnv ? realReactNavigation.useLinkBuilder : () => null;
const useLinkProps = isJestEnv ? realReactNavigation.useLinkProps : () => null;
const useLinkTo = isJestEnv ? realReactNavigation.useLinkTo : () => null;
const useScrollToTop = isJestEnv ? realReactNavigation.useScrollToTop : () => null;
const useRoute = isJestEnv ? realReactNavigation.useRoute : () => ({params: {}});
const useFocusEffect = isJestEnv ? realReactNavigation.useFocusEffect : (callback: () => void) => callback();

export {
// Overriden modules
useIsFocused,
Expand All @@ -60,6 +64,8 @@ export {
useLinkProps,
useLinkTo,
useScrollToTop,
useRoute,
useFocusEffect,
};

export type {NativeNavigationMock};

0 comments on commit da2e668

Please sign in to comment.