Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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
You can’t perform that action at this time.