Skip to content

Instantly share code, notes, and snippets.

@JamesMGreene
Forked from Potherca/qunit.testSkip.js
Last active January 4, 2016 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesMGreene/8617691 to your computer and use it in GitHub Desktop.
Save JamesMGreene/8617691 to your computer and use it in GitHub Desktop.
Duck-punch the `QUnit.test` method to support Mocha-style "pending" tests. UPDATE: As of QUnit v1.16.0, `QUnit.skip` will be a core part of the framework.
/*global QUnit, window, global */
(function (QUnit, global) {
'use strict';
var document = global && global.document;
var pendingTestIds = [];
var QUnit_test = QUnit.test;
QUnit.test = function(testName, expected, callback, async) {
if (typeof expected === 'function' && typeof callback === 'undefined') {
callback = expected;
expected = null;
}
async = async === true;
if (typeof callback === 'function') {
QUnit_test(testName, expected, callback, async);
}
else {
testName = '[PENDING] ' + testName;
// NOTE: If `expected > 0`, the test will FAIL
expected = expected || 0;
if (expected !== 0) {
QUnit_test(testName, expected, callback, async);
}
else {
QUnit_test(testName, expected, function() {
pendingTestIds.push(QUnit.config.current.id);
});
}
}
};
// If running in the browser
if (document && document.getElementById) {
// When the test run is completed, go through all of the pending tests and update their HTML
QUnit.done(function() {
for (var i = 0, len = pendingTestIds.length; i < len; i++) {
var li = document.getElementById(pendingTestIds[i]);
li.className = 'pending';
li.style.background = '#FFFF99';
}
});
}
// Export the global `test` but only if it is exported globally already
if (global.test === QUnit_test) {
global.test = QUnit.test;
}
}(QUnit, window || global || this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment