Skip to content

Commit

Permalink
Core: QUnit.start fails if called with a non-numeric argument
Browse files Browse the repository at this point in the history
Fixes #846
Closes #877
  • Loading branch information
rdugue authored and leobalter committed Oct 18, 2015
1 parent 64fdbac commit ea3e350
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ extend( QUnit, {
// If a test is running, adjust its semaphore
config.current.semaphore -= count || 1;

// If semaphore is non-numeric, throw error
if ( isNaN( config.current.semaphore ) ) {
config.current.semaphore = 0;

QUnit.pushFailure(
"Called start() with a non-numeric decrement.",
sourceFromStacktrace( 2 )
);
return;
}

// Don't start until equal number of stop-calls
if ( config.current.semaphore > 0 ) {
return;
Expand Down
13 changes: 13 additions & 0 deletions test/main/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ QUnit.test( "fails if start is called more than stop", function( assert ) {
"already\\)" ) );
});

QUnit.test( "fails if start is called with a non-numeric argument", function( assert ) {
QUnit.stop();

// Duck-punch to force an Error to be thrown instead of a `pushFailure` call
assert.test.pushFailure = function( msg ) {
throw new Error( msg );
};

assert.throws(function() {
QUnit.start( "ok" );
}, /Called start\(\) with a non\-numeric decrement\./ );
});

QUnit.module( "asyncTest" );

QUnit.asyncTest( "asyncTest", function( assert ) {
Expand Down

0 comments on commit ea3e350

Please sign in to comment.