-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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