Loud Bit

The Web Design & Development Studio of Mr. Darcy Murphy

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:

package.json

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

.babelrc

{
  "presets": [
    "es2015"
  ]
}

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!