Jest, Unexpected Token Import : <p>I start a new react project and I wand to use Jest as testing platform. Despite docs, blogs and many others resources like stackoverflow, I have always an "unexpected token import" error related probably to a babel problem, but my conf seem to be ok. Any help is welcomed.</p>

<p>My Jest conf (in package.json). My package.json has dependencies like babel-jest, babel-preset-es2015, babel-preset-react, etc. </p>

<pre><code> "jest": {
    "testMatch": [
      "**/?(*.)spec.js?(x)"
    ],
    "moduleDirectories": [
      "src",
      "node_modules"
    ],
    "moduleNameMapper": {
      "^lib/(.*)$": "&lt;rootDir&gt;/src/lib/$1",
      "^components/(.*)": "&lt;rootDir&gt;/src/components/$1",
    },
    "transform": {
      "^.+\\.jsx?$": "babel-jest"
    }
</code></pre>

<p>My .babelrc conf :</p>

<pre><code>{
  "presets": [
    ["es2015", { "modules": false }],
    "react"
  ],
  "plugins": [
    ["react-hot-loader/babel"],
    ["transform-object-rest-spread", { "useBuiltIns": true }],
    ["transform-runtime"]
  ],
  "env": {
      "test": {
        "presets": ["es2015", "react"]
      }
  } 
}
</code></pre>

<p>My spec file :</p>

<pre><code>import React from 'react';
import Radio from 'components/ui/radio';
...
</code></pre>

<p>And components/ui/radio (import error is raised on the first line) :</p>

<pre><code>import Container from './container.jsx';
...
</code></pre>

<p>My webpack has two alias named lib and components (define as moduleNameMapper in jest).</p>

<pre><code>...
resolve: {
   mainFiles: ['index', 'main'],
   extensions: ['.js', '.jsx'],
   alias: {
     lib: helpers.getPath('src/lib/'),
     components: helpers.getPath('src/components/'),
   },
   modules: [
     helpers.getPath('src'),
     helpers.getPath('node_modules'),
   ],
}, 
...
</code></pre>
