react-navigation-shared-element icon indicating copy to clipboard operation
react-navigation-shared-element copied to clipboard

Jest Mocking

Open AbdulmalickDimnang opened this issue 4 years ago • 7 comments

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",

AbdulmalickDimnang avatar Apr 06 '21 12:04 AbdulmalickDimnang

Did you find a solution?

giuseppeabn avatar Sep 16 '21 15:09 giuseppeabn

did you find solution

hagar0459 avatar Oct 23 '21 11:10 hagar0459

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)', ],

igormoraesdev avatar Nov 16 '21 05:11 igormoraesdev

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

yasirdev avatar Nov 24 '21 10:11 yasirdev

also getting the issue, no one found a solution?

Dadilium avatar Feb 12 '22 21:02 Dadilium

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

6youss avatar Mar 17 '22 20:03 6youss

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

marklanham avatar Mar 27 '23 13:03 marklanham