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 fails import typeof ActionSheetIOS from './Libraries/ActionSheetIOS/ActionSheetIOS'; #269

Open
arcorreiaa opened this issue Apr 30, 2024 · 4 comments

Comments

@arcorreiaa
Copy link

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
Copy link

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

@PedroAugustoRamalhoDuarte

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
Copy link

Anybody got a solution??

@ZainaliSyed
Copy link

Yes I am also getting this error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants