0

Encountered this error before and seen other answers but the solution does not solve my problem.

in my package.json I have:

 "dependencies": { "axios": "^0.15.2", "babel": "^6.5.2", "babel-core": "^6.13.1", "babel-loader": "^6.0.1", "babel-preset-es2015": "^6.0.15", "babel-preset-node5": "^11.1.0", "babel-preset-react": "^6.0.15", "babel-preset-stage-0": "^6.0.15", "babel-preset-stage-2": "^6.11.0", 

then in my webpack.config.js I have:

module.exports = { entry: './main.js', 

then in my main.js I have:

import "./src"; 

I then run npm test which calls this script:

 "scripts": { "test": "mocha src/**/*.spec.js", 

and then it fails because inside src/components/header/index.spec.js:1 I have: import React from 'react';

cant work out why it wont work

I have a .babelrc file with this in:

{ "sourceMaps": true, "presets": ["es2015", "react", "stage-2"] } 

also in my webpack I have:

module: { loaders: [ { test: /\.js$/, exclude: /node_modules/, loader: 'babel', query: { presets: ['es2015', 'react', 'stage-2'] } }, { test: /\.scss$/, loaders: ["style-loader", "css-loader", "sass-loader"] } ] } 

any ideas?

0

2 Answers 2

1

you can go to babel setup page and select your test framework then it helps you to integrate test framework with babel step by step.may be your test script write this:

"mocha --compilers js:babel-register src/**/*.spec.js"

Sign up to request clarification or add additional context in comments.

1 Comment

saw the other answer first so voted that but will upvote this, thanks
0

When you execute your test by mocha command, it will executes your test script in node.js without ES6, because V8 yet doesn't implemented ES6.

You can use compillers of mocha. You has babel-core, you can use this command (it's better in your case):

mocha src/**/*.spec.js --compilers js:babel-core/register 

Or install babel-register standalone (babel-register module) and use:

mocha --compilers js:babel-register 

See more in: http://jamesknelson.com/testing-in-es6-with-mocha-and-babel-6/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.