React-native – Unexpected import token – testing React Native with Jest

babeljsecmascript-6jestjsreact-native

I'm getting a weird import error when I try to test my react-native app with jest. I have babel-jest, babel-preset-react-native, jest, jest-react-native and react-test-render all installed but get this error message when I run npm test.

● Test suite failed to run

/Users/maftalion/www/stars20/kiosk/node_modules/native-base/index.js:4
import Drawer from './Components/vendor/react-native-drawer';
^^^^^^
**SyntaxError: Unexpected token import**

  at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:316:10)
  at Object.<anonymous> (src/routes/Identification.js:3:17)
  at Object.<anonymous> (src/routes/router.js:4:21)

Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 1 passed, 1 total
Time: 1.011s

Best Answer

Figured it out, basically throw any node modules that use es6 syntax in transformIgnorePatterns.

"transformIgnorePatterns": [
   "node_modules/(?!react-native|native-base|react-clone-referenced-element)"
],
Related Topic