From 255e5dfee9178a2afdfcd9ce68d812e55beed3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Thu, 2 Oct 2014 16:11:33 +0200 Subject: [PATCH] Assert: Add alias for throws called 'raises' Brings back the original method name, for compatibility with environments that consider 'throws' a reserved word. Fixes #663 --- src/assert.js | 7 +++++++ test/assert.js | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/assert.js b/src/assert.js index 733fa0d61..6f9da0abb 100644 --- a/src/assert.js +++ b/src/assert.js @@ -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" ]; +}()); diff --git a/test/assert.js b/test/assert.js index 8d379c931..1c89d5a91 100644 --- a/test/assert.js +++ b/test/assert.js @@ -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"; + }); +});