So Babel recently had a disruptive major update (version 6) 2 days ago on Oct 29, 2015.

Right afterwards I tried to write some mocha tests in ES6 (ES2015) and it was quite frustrating to get working.

So to save someone else the same trouble:

Babel is now babel-core. So when you would have use babel/register you will need to do babel-core/register. This actually happened before version 6 but just incase anyone is still referencing the old way.

With Babel 6 you will need to include the proper plugins to get babel to work as you like. There are also presets you can use that are bundles of plugins. For my uses case I could get away with just the ES2015 and React presets.

First install the presets:

$ npm install babel-preset-es2015 babel-preset-react --save-dev

Then edit the scripts block in package.json to look like this:

"scripts": {
  "test": "mocha --require babel-core/register"

Finally, add a file called .babelrc to your project root telling Babel to use the presets:

 "presets": [ "react", "es2015" ]

Now you should be able to write your tests using ES2015.

© 2017. All Rights Reserved.

Proudly published with Ghost