Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest failed after upgrade to react-native 0.64 #703

Closed
McSam94 opened this issue Mar 19, 2021 · 10 comments · Fixed by #704
Closed

Jest failed after upgrade to react-native 0.64 #703

McSam94 opened this issue Mar 19, 2021 · 10 comments · Fixed by #704
Labels
docs good first issue Good for newcomers

Comments

@McSam94
Copy link
Contributor

McSam94 commented Mar 19, 2021

Describe the bug

Recently I upgraded my project to 0.64 version and faced this issue when I run jest. The same error happened even after I tried with a fresh react-native project with package react-navigation.

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:439:6)

Expected behavior

Jest should be completed without error.

Steps to Reproduce

  1. react-native init
  2. install all the react-navigation packages
  3. set up the testing environment as documented. (https://callstack.github.io/react-native-testing-library/docs/react-navigation#setting-up-the-test-environment)
  4. run jest

Screenshots

Screenshot 2021-03-19 at 8 29 48 PM

Versions

Screenshot 2021-03-19 at 8 30 20 PM

Please help. Thanks in advance 🙏🏿

@thymikee
Copy link
Member

Check the path to the file that has unsupported syntax (type keyword), it's the most important one. It points to a file located inside node_modues/@react-native/. So, you'll need to add @react-native next to @react-navigation in the transformIgnorePatterns config.

Would you like to contribute a fix to the docs? :)

transformIgnorePatterns: [
-  'node_modules/(?!(jest-)?react-native|@react-native-community|@react-navigation)',
+  'node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)',
]

@thymikee thymikee added docs good first issue Good for newcomers labels Mar 19, 2021
@McSam94
Copy link
Contributor Author

McSam94 commented Mar 19, 2021

Hi, @thymikee thanks for the help. Unfortunately, I ran into another error mocking react-native/Libraries/Animated/src/NativeAnimatedHelper after I updated the patterns.

Screenshot 2021-03-19 at 8 41 56 PM

@thymikee
Copy link
Member

Check if react-native/Libraries/Animated/src/NativeAnimatedHelper is actually there. It's an internal file, so it may have been moved somewhere else

@McSam94
Copy link
Contributor Author

McSam94 commented Mar 19, 2021

ahh okay, replaced with jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); works 👍🏿

@thymikee
Copy link
Member

How about that PR you'd like to send to our docs? :)

@McSam94
Copy link
Contributor Author

McSam94 commented Mar 19, 2021

Sure bro. I'll create a PR shortly

@daviseares
Copy link

Check the path to the file that has unsupported syntax (type keyword), it's the most important one. It points to a file located inside node_modues/@react-native/. So, you'll need to add @react-native next to @react-navigation in the transformIgnorePatterns config.

Would you like to contribute a fix to the docs? :)

transformIgnorePatterns: [
-  'node_modules/(?!(jest-)?react-native|@react-native-community|@react-navigation)',
+  'node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)',
]

This doesnt work for me. I change my transformIgnorePatterns' but i cant solution this issue

jest.config.js

module.exports = {
  preset: '@testing-library/react-native',
  setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
  transformIgnorePatterns: [
    'node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)',
    'node_modules/(?!(@react-native|react-native)/)',
    // 'node_modules/(?!react-native|@react-native|@react-navigation/.*|@react-native-async-storage|react-native-gesture-handler/.*)',
    'node_modules/(?!(react-native-cookies|@sentry/react-native)/)',
  ],
  setupFiles: [
    './node_modules/react-native-gesture-handler/jestSetup.js',
    '<rootDir>/jest.setup.js',
  ],
  moduleNameMapper: {
    '\\.svg': '<rootDir>/__mocks__/svgMock.js',
  },
  collectCoverage: false,
  coverageDirectory: '__coverage__',
  coveragePathIgnorePatterns: ['/node_modules/', '.*.svg', '.*.png'],
}

@YaroslavRenhevych
Copy link

I have the same problem. Your fix does not work for me.

@Jaserto
Copy link

Jaserto commented Sep 25, 2022

any solution?

@mdjastrzebski
Copy link
Member

@Jaserto, @YaroslavRenhevych please refer out the recommended RNTL setup in our examples/basic. If the problem persists then please create a separate issue with repro repository, preferably based on the examples/basic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants