Skip to content

Instantly share code, notes, and snippets.

@FND
Created March 9, 2009 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FND/76340 to your computer and use it in GitHub Desktop.
Save FND/76340 to your computer and use it in GitHub Desktop.
/**
* Checks that the given expression throws an exception of the expected type, with an optional message.
*
* @example raises( function() { return foo.bar; }, "TypeError", "invalid property access raises TypeError exception" );
*
* @param Function expression
* @param String expected exception type
* @param String message (optional)
*/
function raises(expression, expected, message) {
try {
push(false, expression(), expected, message);
} catch(ex) {
console.log(message, ex.name, ex);
push(ex.name == expected, ex.name, expected, message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment