FND / jquery

jQuery plugins

This URL has Read+Write access

jquery / qunit.raiseAssertion.js
100644 36 lines (30 sloc) 1.013 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* extension of the QUnit framework to support exception handling
* cf. http://dev.jquery.com/ticket/4318
*/
 
(function($) {
 
$.extend(window, {
raises: raises
});
 
/**
* 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) {
push(ex.name == expected, ex.name, expected, message);
}
}
 
// duplicated private function from testrunner.js
function push(result, actual, expected, message) {
message = message || (result ? "okay" : "failed");
QUnit.ok( result, result ? message + ": " + expected : message + ", expected: " + jsDump.parse(expected) + " result: " + jsDump.parse(actual) );
}
 
})(jQuery);