Skip to content
Sasha Boginsky edited this page Sep 2, 2020 · 2 revisions

Tools

We use Grunt and Karma to run our tests, and Mocha, Sinon, and Chai to implement them.

  • Grunt is a task runner written in Node.js.
  • Karma is a test runner. It allows us to test our code in multiple browsers and devices.
  • Mocha is a test framework running on Node.js and in the browser. It provides asynchronous test support.
  • Sinon is a library, compatible with any JavaScript unit testing framework, for writing standalone test spies, stubs and mocks.
  • Chai is a library, compatible with any JavaScript unit testing framework, which provides helpers to perform assertions against your code.

Run Tests

To run tests in the test/ folder:

npm test

This command is just a wrapper around the grunt test task, which runs ESLint and Karma tasks.

  • ESLint is a JavaScript code quality tool.

Configuration

In test/karma.conf.js, you can find the available browser options we include:

// start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - ChromeHeadless
browsers: ['ChromeHeadless'],

All available browser launchers: https://npmjs.org/browse/keyword/karma-launcher

Test Syntax

Running a single test block

Attach a .only() function call to the describe or it test block you want to execute.

EXAMPLE:

it('tests feature 1', function() {
  // I won't run :(
});

it.only('tests feature 2', function() {
  // I'll run :)
});

it('tests feature 3', function() {
  // I won't run :(
});

Skipping tests

Attach .skip() function call. Works the same way as .only().

Note

To make your code production ready, remember to remove your .only() and .skip() calls. They are meant for development purposes only.