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 124 forks source link

[Jest] Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function #173

Open LaurenceM10 opened 3 years ago

LaurenceM10 commented 3 years ago

I'm getting this error when I run tests Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. I'm using jest and RNTL. The line of the problem is when declare the SharedElement component:

<SharedElement id={`${id}${company?.logoUrl}`}>

Here my depedencies and devDependencies

"@apollo/client": "^3.3.18",
    "react": "17.0.1",
    "react-native": "0.64.1",
    "react-native-shared-element": "^0.7.0",
    "react-navigation-shared-element": "^5.0.0-alpha1",
  },
  "devDependencies": {
    "@testing-library/react-hooks": "^7.0.0",
    "@testing-library/react-native": "^7.2.0",
    "babel-jest": "^26.6.3",
    "jest": "^26.6.3",
    "react-test-renderer": "17.0.1"
}
LaurenceM10 commented 3 years ago

I also have mocked:

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

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

Did you find a solution?

mjavady commented 3 years ago

I'm stuck with this too.

LaurenceM10NS commented 3 years ago

I haven't found a solution yet @giuseppeabn

bencreynolds commented 2 years ago

Anyone find a solution?