react-native-community / upgrade-support

A central community-backed place to request and give help when upgrading your app.
MIT License
259 stars 2 forks source link

jest fails import typeof ActionSheetIOS from './Libraries/ActionSheetIOS/ActionSheetIOS'; #269

Open arcorreiaa opened 6 months ago

arcorreiaa commented 6 months ago

alguem consegue me ajudar com isso? não consigo rodar o jest de forma nenhuma

alysson.correia@CORPFCX147-MC mapp % yarn test src/screens/Home/Home.test.tsx yarn run v1.22.22 warning ../../../package.json: No license field $ jest src/screens/Home/Home.test.tsx FAIL src/screens/Home/Home.test.tsx ● Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
 • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation

Details:

/Users/alysson.correia/Documents/code/mapp/node_modules/react-native/index.js:14
import typeof ActionSheetIOS from './Libraries/ActionSheetIOS/ActionSheetIOS';
^^^^^^

SyntaxError: Cannot use import statement outside a module

  2 | import React from 'react';
  3 | import {expect, it, describe} from '@jest/globals';
> 4 | import {render} from '@testing-library/react-native';
    | ^
  5 | import {Home} from '.';
  6 | import {HomeComponent} from './Home';
  7 |

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
  at Object.require (node_modules/@testing-library/react-native/src/helpers/host-component-names.tsx:3:1)
  at Object.require (node_modules/@testing-library/react-native/src/fire-event.ts:11:1)
  at Object.require (node_modules/@testing-library/react-native/src/pure.ts:3:1)
  at Object.require (node_modules/@testing-library/react-native/src/index.ts:1:1)
  at Object.require (src/screens/Home/Home.test.tsx:4:1)

Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 0.249 s Ran all test suites matching /src\/screens\/Home\/Home.test.tsx/i. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. alysson.correia@CORPFCX147-MC mapp %

Stewartarmbrecht commented 3 months ago

I'm getting the same error. Did you figure this out?

PedroAugustoRamalhoDuarte commented 2 months ago

Probably is a miss configuration from jest-expo, Try to add this in you package.json:

"jest": {
  "preset": "jest-expo",
  "transformIgnorePatterns": [
    "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)"
  ]
}

More infos

jotilohana commented 1 month ago

Anybody got a solution??

ZainaliSyed commented 1 month ago

Yes I am also getting this error