testing-library / native-testing-library

šŸ³ Simple and complete React Native testing utilities that encourage good testing practices.
https://native-testing-library.com
MIT License
516 stars 44 forks source link

syntax error when running native-testing-library with expo #116

Closed ivan-navarro-75 closed 4 years ago

ivan-navarro-75 commented 4 years ago

Relevant code or config:

const expoPreset = require('jest-expo/jest-preset')
const jestPreset = require('@testing-library/react-native/jest-preset')

module.exports = Object.assign({}, expoPreset, jestPreset, {
  setupFiles: [...expoPreset.setupFiles, ...jestPreset.setupFiles],
  preset: '@testing-library/react-native',
})

What you did:

when I've tried to run my test

What happened:

I got this error:

node_modules/expo/build/Expo.fx.js:1
({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import './environment/validate.fx';

SyntaxError: Cannot use import statement outside a module

Reproduction:

Problem description:

Suggested solution:

Can you help us fix this issue by submitting a pull request?

ivan-navarro-75 commented 4 years ago

Iā€™ve found the solution,

basically I had to use the @testing-library/react-native preset and extend it with the jest-expo preset content. To be honest still donā€™t know why it didnā€™t work with the solution you have in the documentation.

module.exports = { preset: '@testing-library/react-native', haste: { defaultPlatform: 'ios', platforms: ['android', 'ios', 'native'] }, transform: { '^.+\.(js|ts|tsx)$': 'babel-jest', '^.+\.... }