React-native-screens: what is a proper jest mock for react-native-screens?

Created on 4 Dec 2019  路  3Comments  路  Source: software-mansion/react-native-screens

Most helpful comment

For me, working with this:

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

All 3 comments

For me, working with this:

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

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;

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(),
}));
Was this page helpful?
0 / 5 - 0 ratings

Related issues

piotrfalba picture piotrfalba  路  5Comments

ukasiu picture ukasiu  路  4Comments

bitttttten picture bitttttten  路  3Comments

hadnet picture hadnet  路  4Comments

jeveloper picture jeveloper  路  5Comments