I am testing a view for Home component for React Native 0.68.2/jest 29.0. The simple test case is copied from jest doc:
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { render, cleanup, screen, fireEvent } from "@testing-library/react-native";
import App from '../App';
describe ('App ', () => {
//afterEach(cleanup);
test ('shall stack screens', async () => {
const component = (<NavigationContainer>
<App />
</NavigationContainer>);
const {getByText} = render(component);
await waitFor(() => getByText('AppSplash'));
})
})
Here is the App.js:
import React, {useState, useContext, Component} from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import SplashScreen from './src/components/splashscreen/SplashScreen';
import SysError from './src/components/app/SysError';
import Bye from "./src/components/app/Bye";
import Verif1 from './src/components/signup/Verif1';
import Signup from './src/components/signup/Signup';
import TermCondition from './src/components/common/TermCondition';
import AppScreen from "./src/components/app/AppScreen";
const Stack = createStackNavigator();
export default function App() {
return (
<SafeAreaProvider>
<NavigationContainer>
<Stack.Navigator InitialRouteName="AppSplash">
<Stack.Screen name="AppSplash" component={SplashScreen} options={{headerShown:false}}/>
<Stack.Screen name="AppSysError" component={SysError} options={{headerShown:false}} />
<Stack.Screen name="AppScreen" component={AppScreen} options={{headerShown:false}} />
<Stack.Screen name="AppVerif1" component={Verif1} options={{headerShown:false}} />
<Stack.Screen name="AppSignup" component={Signup} options={{headerShown:false}} />
<Stack.Screen name="TermCondition" component={TermCondition} options={{headerShown:false}} />
<Stack.Screen name="Bye" component={Bye} options={{headerShown:false}} />
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
);
};
Here is the output of yarn jest.
ā Invalid return value:
`process()` or/and `processAsync()` method of code transformer found at
"/Users/macair/Documents/code/js/xyz_app6/node_modules/react-native/jest/assetFileTransformer.js"
should return an object or a Promise resolving to an object. The object
must have `code` property with a string of processed code.
This error may be caused by a breaking change in Jest 28:
https://jestjs.io/docs/upgrading-to-jest28#transformer
Code Transformation Documentation:
https://jestjs.io/docs/code-transformation
I just started using jest and none of solutions found this error works.