7

Im using JEST to test my app. But Im getting an error from the test file --

import xyz from './XYZ.js';
    ^^^^^^
SyntaxError: Unexpected token import

Then I created a .babelrc file and it has the following code --

{
  "presets": [
    "es2015"
  ]
}

After this, whichever file I have imported in the test file does not throw this error. But if one of the imported files (like XYZ.js) have import statement in itself, then it gives the same error on that file.

My package.json devDependencies (significant packages) --

"devDependencies": {
    "babel-jest": "^19.0.0",
    "babel-preset-es2015": "^6.22.0",
    "eslint": "2.0.0",
    "eslint-plugin-react": "latest",
    "express": "^4.12.2",
    "jest": "^19.0.1",
    "react": "^15.3.2",
    "react-dom": "^15.3.2",
    "react-router": "^2.8.1"
  },

Can anyone point out what I have missed?

Ivin
  • 4,435
  • 8
  • 46
  • 65

1 Answers1

-1

Try using

import { xyz } from './XYZ.js';

Also make sure you exported the module

export function xyz() {}

And check out Babel stage-0

Alex S
  • 37
  • 3
  • Yes, it is exported. Its being used in other files (non test files) and it works there. Only in test files it fail. – Ivin Mar 02 '17 at 07:26