Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what is a proper jest mock for react-native-screens? #247

Closed
sibelius opened this issue Dec 4, 2019 · 4 comments
Closed

what is a proper jest mock for react-native-screens? #247

sibelius opened this issue Dec 4, 2019 · 4 comments

Comments

@sibelius
Copy link

sibelius commented Dec 4, 2019

No description provided.

@msvargas
Copy link

For me, working with this:

jest.mock('react-native-screens', () => {
  const RealComponent = jest.requireActual('react-native-screens');
  RealComponent.enableScreens = function() {};
  return RealComponent;
});

@sibelius
Copy link
Author

fixed like this:

const View = require('react-native').View;

export const enableScreens = jest.fn();
export const ScreenContainer = View;
export const Screen = View;
export const NativeScreen = View;
export const NativeScreenContainer = View;
export const ScreenStack = View;
export const ScreenStackHeaderConfig = View;
export const ScreenStackHeaderSubview = View;
export const ScreenStackHeaderRightView = View;
export const ScreenStackHeaderLeftView = View;
export const ScreenStackHeaderTitleView = View;
export const ScreenStackHeaderCenterView = View;

@badsyntax
Copy link

I used this approach. Within my jest setup file: ./jest/setup.js:

jest.mock('react-native-screens', () => ({
  ...jest.requireActual('react-native-screens'),
  enableScreens: jest.fn(),
}));

@SMJ93
Copy link

SMJ93 commented Jun 9, 2021

If you are using createBottomTabNavigator you will also need to mock ScreenContainer:

// __mocks__/react-native-screens.tsx
import { View } from "react-native";

export const enableScreens = jest.fn();
export const screensEnabled = jest.fn().mockReturnValue(false);
export const ScreenContainer = View;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants