I am getting the error of [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null. once I am trying to run tests in my typescript expo project.
I followed the steps in here but afterwards I am getting the following error:
Test suite failed to run
Ensure `@react-native-async-storage/async-storage` is installed and linked.
2 | import React, { useRef, useState } from "react";
3 | import LottieView from "lottie-react-native";
> 4 | import { fetchAuthSession } from "aws-amplify/auth";
| ^
5 | import { post } from "aws-amplify/api";
6 | import {
7 | GestureHandlerRootView,
The linking should be handled automatically. my test:
it("renders correctly", () => {
const { getByText } = render(<UserCard />);
const element = getByText("Greetings!");
expect(element).toBeTruthy();
});
my package.json
{
"name": "amplify-graphql-prework",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"test": "jest"
},
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg|@expo/vector-icons)"
],
"setupFiles": [
"./jestSetupFile.ts"
]
},
"dependencies": {
"@aws-amplify/react-native": "^1.0.5",
"@aws-amplify/ui-react-native": "^2.0.3",
"@react-native-async-storage/async-storage": "^1.21.0",
"@react-native-community/netinfo": "^11.1.1",
"@react-native-picker/picker": "2.4.10",
"aws-amplify": "^6.0.5",
"expo": "~49.0.15",
"expo-dev-client": "~2.4.12",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"jest": "^29.2.1",
"jest-expo": "~49.0.0",
"lottie-react-native": "5.1.6",
"react": "18.2.0",
"react-native": "0.72.6",
"react-native-gesture-handler": "~2.12.0",
"react-native-get-random-values": "^1.10.0",
"react-native-safe-area-context": "4.6.3",
"react-native-url-polyfill": "^2.0.0",
"react-test-renderer": "^18.2.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@testing-library/react-native": "^12.4.1",
"@types/jest": "^29.5.11",
"@types/react": "~18.2.14",
"typescript": "^5.1.3"
},
"private": true
}