Loud Bit

A Web Design & Development Studio

Testing ES6 Code with Mocha

There's a few articles out there, but some of them are out of date. Here's the minimum I needed for a project. Install mocha, babel-preset-es2015, and babel-register, then add the following to your project:


"test": "mocha --compilers js:babel-register --require babel-polyfill",


  "presets": [

The real gotcha is the .babelrc. I'd originally had the babel config in the package.json, but running the tests didn't work until the config was moved there.

The more you know!