import issue using jest with react-native app

45 views Asked by At

I'm new to React native, expo and Jest testing and I don't figure out how to solve the import problem I have with my test.

running 'npm run test' returns me this :

SyntaxError: Cannot use import statement outside a module

  1 | import React from 'react';
  2 | import { render, fireEvent } from '@testing-library/react-native';
> 3 | import Login from '../Login';

My package.json file looks like this :

{
  "name": "app",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "test": "jest"
  },
  "dependencies": {
    "@react-navigation/native-stack": "^6.9.17",
    "expo": "~49.0.15",
    "expo-checkbox": "~2.4.0",
    "expo-dev-client": "~2.4.12",
    "expo-image-picker": "~14.3.2",
    "expo-linear-gradient": "~12.3.0",
    "expo-status-bar": "~1.6.0",
    "native-base": "^3.4.28",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-dialog": "^9.3.0",
    "react-native-easy-grid": "^0.2.2",
    "react-native-mlkit-ocr": "^0.3.0",
    "react-native-paper": "^5.11.1",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "~3.22.0",
    "react-native-svg": "13.9.0",
    "react-navigation": "^5.0.0",
    "tesseract.js": "^5.0.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "jest": "^29.7.0"
  },
  "jest": {
    "preset": "react-native"
  },
  "private": true
}

Trying to debug, I think there's maybe something to do with tranformIgnorePatterns but I don't know how to fix this.

0

There are 0 answers