I have set up a really, really simple component in react native using typescript. My goal is just to get Jest set up and a simple test to pass. Here is the code for App.tsx:
import React from 'react';import { StyleSheet, Text, View } from 'react-native';export default function App() { return (<View style={styles.container}><Text>Hello World!</Text></View> );}const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', },});
and the test:
import React from 'react';import App from '../App';import { create } from "react-test-renderer";test('renders correctly', () => { const tree = create(<App />); expect(tree.toJSON()).toMatchSnapshot();});
'Hello World' renders as expected but when I run the test I get:
console.error Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
And indeed when I check the exported function 'App's type it is a React.Element not a component. But why is that? It is returning an element but I thought thats what a component was supposed to do. The export itself is a stateless function so I am a bit confused...