Mocha QUnit UI
An interface for Mocha that implements QUnit's API.
Mocha ships with a QUnit interface, but it lacks assertions, support for
expected assertion count, and the asyncTest
method (among other things). This
is an alternate implementation that fully supports the entire QUnit
API. It may be run either in Node.js or the browser.
The goal is to get as close as possible to being able to run QUnit tests
unaltered in Mocha.
Installation
$ npm install mocha-qunit-ui --save-dev
Usage
Node.js
From the command line:
$ mocha --ui mocha-qunit-ui test/test-file-1.js
Programatically:
// Load mocha-qunit-uirequire("mocha-qunit-ui");// Tell mocha to use the interface.var mocha = new Mocha({ ui:"qunit"});// Add your test filesmocha.addFile("path/to/my/testfile.js");// Run your testsmocha.run(function(failures){ process.exit(failures);});
Browser environments
Declare an HTML file with the following markup to run tests in the browser:
Tests
You can also use qunit-mocha-ui from Grunt with the
grunt-mocha
task. Here's an
example Gruntfile.js
:
module.exports = function(grunt) { grunt.loadNpmTasks('grunt-mocha'); grunt.initConfig({ mocha: { test:{ options:{ mocha: { ui: 'qunit' } }, src: [ "test/test-file-1.js" ] } } }); grunt.registerTask('default', ['mocha']);};
Known differences from QUnit API
- The global variable
module
is reserved in Node.js. If you want to define a QUnit module in that environment, use theQUnit.module
alias.
Running tests
- Install dependencies:
npm install
- Update QUnit submodule
git submodule update --init --recursive
npm test
You can run QUnit's test suite by opening test/qunit.html
in a browser.
License
Copyright (c) 2013 Mike Pennisi
Licensed under the MIT license.