Skip to content

Commit

Permalink
Assert: Extend throws to accept Error instances
Browse files Browse the repository at this point in the history
Fixes gh-476
Closes gh-506
  • Loading branch information
leobalter authored and jzaefferer committed Jan 29, 2014
1 parent 48761bb commit b10cd7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/assert.js
Expand Up @@ -142,6 +142,12 @@ assert = QUnit.assert = {
ok = true;
expectedOutput = null;

// expected is an Error object
} else if ( expected instanceof Error ) {
ok = actual instanceof Error &&
actual.name === expected.name &&
actual.message === expected.message;

// expected is a regexp
} else if ( QUnit.objectType( expected ) === "regexp" ) {
ok = expected.test( errorString( actual ) );
Expand Down
10 changes: 9 additions & 1 deletion test/test.js
Expand Up @@ -497,7 +497,7 @@ test("propEqual", function( assert ) {
});

test("throws", function( assert ) {
expect(9);
expect(10);
function CustomError( message ) {
this.message = message;
}
Expand Down Expand Up @@ -584,6 +584,14 @@ test("throws", function( assert ) {
"some error description",
"handle string typed thrown errors"
);

assert.throws(
function() {
throw new Error( "foo" );
},
new Error( "foo" ),
"assert when a function throws an 'Error' object"
);
});

if (typeof document !== "undefined") {
Expand Down

0 comments on commit b10cd7f

Please sign in to comment.