Writing Jasmine unit tests in ES6

Published: Sat Apr 18 2015

Previously I showed how to write application code using ES6, but wouldn't it be nice to use ES6 when writing unit tests as well? In the following post I will demonstrate how to write Jasmine tests using ES6 syntax.

Setting up the test environment is fairly easy, but to move things along I've included my sample package.json configuration

test-context.js

This is where you tell the test runner where your files are located. Based on the configuration above my test files are located in ./source and they all end in -spec.js. The extra boolean flag indicates if you want it to go looking for files in subdirectories under ./source.

context.keys contains an array of test files.

Now that the environment is bootstrapped it's time to write some tests!

To keep it simple we will be writing tests for a simple calculator implementation.