Unit Testing Node ES6 Modules with TypeScript

Just when you think you've got TypeScript figured out and are using es6 (es2015) module loading you discover your unit tests fail. Don't worry. It's not you, it's Mocha.

This just a quick note to give you some direction on how to enable ES6 module loading within your TypeScript files while keeping your unit tests from throwing errors.

First, you’ll need to be ok with using the babel compiler. While it won’t be used for your production code, the babel compiler with the es2015 preset essentially down-samples your code to es5 so mocha can run it.