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

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

Open LaurenceM10 opened this issue 3 years ago • 5 comments

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 avatar Jul 06 '21 06:07 LaurenceM10

I also have mocked:

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

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

LaurenceM10 avatar Jul 06 '21 06:07 LaurenceM10

Did you find a solution?

giuseppeabn avatar Sep 16 '21 15:09 giuseppeabn

I'm stuck with this too.

mjavady avatar Oct 07 '21 18:10 mjavady

I haven't found a solution yet @giuseppeabn

LaurenceM10NS avatar Oct 07 '21 19:10 LaurenceM10NS

Anyone find a solution?

bencreynolds avatar Dec 04 '21 01:12 bencreynolds