jest unexpected identifier when I add setup files

Viewed 86

Why I get this error:

    C:\PC\node_modules\@react-native\polyfills\error-guard.js:14
    type ErrorHandler = (error: mixed, isFatal: boolean) => void;
         ^^^^^^^^^^^^

    SyntaxError: Unexpected identifier

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (node_modules/react-native/jest/setup.js:16:6)

This comes when I add this line:

    "setupFiles": ["./node_modules/react-native-gesture-handler/jestSetup.js"],

I want to test my navigation

NavigationTest.js

import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { render } from '@testing-library/react-native';
import { NativeStackWrapper } from '../src/navigation/CurvedBottomTab';

jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');

describe('test the Navigation', () => {

  it('should render the curved tab navigator without errors', () => {
    const { debug } = render(
    <NavigationContainer>
      <NativeStackWrapper />
    </NavigationContainer>)

    debug();
  });

});

Package.json

...
  "jest": {
    "preset": "jest-expo",
    "setupFiles": ["./node_modules/react-native-gesture-handler/jestSetup.js"],
    "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)|(?!lodash-es)"
    ]
  },
0 Answers
Related