"stop the world" assertion #332

jzaefferer opened this Issue Oct 18, 2012 · 4 comments


None yet
3 participants

jzaefferer commented Oct 18, 2012

Feature request from Yehuda: An assertion method that, when it fails, stops the entire testsuite, preventing any further tests to run.


  • jshint running in testsuite could stop any further tests from running
  • enviroment test could prevent tests to run, e.g. don't run anything if page is loaded via file: protocol

Krinkle commented Oct 22, 2012

Maybe a static method instead of an assertion method, that way it can be the result of any assertion (as opposed to whatever assertion(s) we stick it on), like QUnit.abort instead of assert.equalOrAbort.


rodneyrehm commented Nov 6, 2012

From an API point of view this would be charming:

test("assertion with stop on failure", function() {
  equal(true, false, "hello world").orAbort("Aborting tests because I feel like it");

This prevents you from cluttering the namespace with more functions ('equal()', 'equalOrAbort()'), is nicer to read and allows the test to pass additional data to the abort-handler. Also this is "future-proof" in the way that you could always add other callback-registries to be executed on failure. As the assertion functions currently have no return value, this should be backward-compatible.

Some code fragments @jzaefferer asked for:

// yes, we're using an Exception for message-passing and deliberate control-flow-ejection. Sue me!
var AbortTestRun = function(){ /* ... */ };

// container for failure handlers
var failureHandlers = {
    orAbort: function(message) {
        throw new AbortTestRun(message);
var voidHandlers = {
    orAbort: function(){}

QUnit.assert.equal = function( actual, expected, message ) {
    var result = expected == actual;
    QUnit.push( result, actual, expected, message );
    return result ? voidHandlers : failureHandlers;

// in Test.prototype.run extend the catch() {} to check for `e instanceof AbortTestRun`,
// if so, kill the queue and show the abort-message

jzaefferer commented Dec 6, 2012

The two examples in the description seem saner than the one in the proposed API comment. I'd rather see something like QUnit.abort();

From Scott on IRC. So for jQuery's testsuite, something like this:

if ( isLocal ) {
  QUnit.abort( "Cannot run tests over the file protocol." );

The message argument would be output to clarify the abort.


jzaefferer commented Feb 13, 2014

We've reviewed this again, more than a year later, and decided not to implement this. There's neither enough interest nor common value.

@jzaefferer jzaefferer closed this Feb 13, 2014

@Krinkle Krinkle added the discarded label Feb 13, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment