IjzerenHein / react-navigation-shared-element

React Navigation bindings for react-native-shared-element 💫
https://github.com/IjzerenHein/react-native-shared-element
MIT License
1.27k stars 123 forks source link

Jest Mocking #157

Open AbdulmalickDimnang opened 3 years ago

AbdulmalickDimnang commented 3 years ago

I'm getting TypeError: (0 , _reactNavigationSharedElement.createSharedElementStackNavigator) is not a function when testing with jest yarn test or npm jest

I have added these mocks to jest Setup file

jest.mock('react-native-shared-element', () => {
  return () => ({});
});

jest.mock('react-navigation-shared-element', () => {
  return () => ({
    createSharedElementStackNavigator: jest.fn(),
  });
});

But still failing to test with Jest

I'm using "react-native": "0.64.0", "jest": "^25.1.0", "react-native-shared-element": "^0.7.0", "react-navigation-shared-element": "3.0.0",

giuseppeabn commented 3 years ago

Did you find a solution?

hagar0459 commented 3 years ago

did you find solution

igormoraesdev commented 3 years ago

try to add this in you jest file:

transformIgnorePatterns: [ 'node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation|@react-native-vector-icons|react-navigation-shared-element)', ],

yasirdev commented 3 years ago

@igormoraesdev I couldn't find it working :( can you please share complete code snippet?

Dadilium commented 2 years ago

also getting the issue, no one found a solution?

6youss commented 2 years ago

Hello i just replaced them with this and it works


jest.mock('react-navigation-shared-element', () => {
  return {
    createSharedElementStackNavigator: jest.fn(),
  };
});

just return an object instead of a function

marklanham commented 1 year ago

See also: https://github.com/IjzerenHein/react-navigation-shared-element/issues/274 as this is related.