Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error jest: Warning: React.createElement: type is invalid

I'm testing a React Native app build with Typescript.

Jest Output:

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object

Ps. Rn work anyway also render method, but i don't understand where is this bug in the code. Anyone can help me?

App.test.tsx

import 'react-native';
import * as React from 'react';
import App from '../App';

import renderer from 'react-test-renderer';

it('renders correctly', () => {
  renderer.create(<App />);
});

like image 634
dev Avatar asked Jun 20 '19 16:06

dev


1 Answers

Found the solution here: Why is my jest test failing in React native with typescript?

If you are using react-native with expo, add this to your package.json:

"jest": {
    "preset": "jest-expo",
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ]
},
like image 101
Aakshaye Avatar answered Nov 06 '22 20:11

Aakshaye