Skip to content

Commit

Permalink
Assert: Add alias for throws called 'raises'
Browse files Browse the repository at this point in the history
Brings back the original method name, for compatibility with environments
that consider 'throws' a reserved word.

Fixes qunitjs#663
  • Loading branch information
jzaefferer committed Oct 3, 2014
1 parent 852cc7c commit 255e5df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ QUnit.assert = Assert.prototype = {
}
}
};

// Provide an alternative to assert.throws(), for enviroments that consider throws a reserved word
// Known to us are: Closure Compiler, Narwhal
(function() {
/*jshint sub:true */
Assert.prototype.raises = Assert.prototype[ "throws" ];
}());
7 changes: 7 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,10 @@ QUnit.test( "throws", function( assert ) {
"handle string typed thrown errors"
);
});

QUnit.test( "raises, alias for throws", function( assert ) {
assert.expect( 1 );
assert.raises(function() {
throw "my error";
});
});

0 comments on commit 255e5df

Please sign in to comment.