upgrade-support icon indicating copy to clipboard operation
upgrade-support copied to clipboard

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

Open arcorreiaa opened this issue 1 year ago • 7 comments

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 %

arcorreiaa avatar Apr 30 '24 01:04 arcorreiaa

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

Stewartarmbrecht avatar Jul 25 '24 19:07 Stewartarmbrecht

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

Anybody got a solution??

jotilohana avatar Sep 19 '24 09:09 jotilohana

Yes I am also getting this error

ZainaliSyed avatar Oct 08 '24 17:10 ZainaliSyed

Me too

utku-guclu avatar Jan 04 '25 16:01 utku-guclu

Any solutions?

cleversonhabiitech avatar Feb 23 '25 18:02 cleversonhabiitech

any solution expo happened too

zoom2009 avatar Mar 08 '25 18:03 zoom2009