Bug Tracker

Ticket #4318: QUnit_raisesAssertion.patch

File QUnit_raisesAssertion.patch, 1.1 KB (added by FND, 11 years ago)
  • testrunner.js

     
    224224        expect: expect,
    225225        ok: ok,
    226226        equals: equals,
     227        raises: raises,
    227228        start: start,
    228229        stop: stop,
    229230        reset: reset,
     
    590591        push(expected == actual, actual, expected, message);
    591592}
    592593
     594/**
     595 * Checks that the given expression throws an exception of the expected type, with an optional message.
     596 *
     597 * @example raises( function() { return foo.bar; }, "TypeError", "invalid property access raises TypeError exception" );
     598 *
     599 * @param Function expression
     600 * @param String expected exception type
     601 * @param String message (optional)
     602 */
     603function raises(expression, expected, message) {
     604        try {
     605                push(false, expression(), expected, message);
     606        } catch(ex) {
     607                push(ex.name == expected, ex.name, expected, message);
     608        }
     609}
     610
    593611function push(result, actual, expected, message) {
    594612        message = message || (result ? "okay" : "failed");
    595613        QUnit.ok( result, result ? message + ": " + expected : message + ", expected: " + jsDump.parse(expected) + " result: " + jsDump.parse(actual) );