B2G/gecko/services/sync/tps/extensions/mozmill/resource/modules/assertions.js
/* Tests whether a code block throws the expected exception
     class. helper for throws() and doesNotThrow()

     adapted from node.js's assert._throws()
     https://github.com/joyent/node/blob/master/lib/assert.js
  */
Tests whether a code block throws the expected exception
class. helper for throws() and doesNotThrow()


Tests whether a code block throws the expected exception class . helper for throws () and doesNotThrow ()
function Expect__throws(shouldThrow, block, expected, message) {
    var actual;
    if (typeof expected === 'string') {
      message = expected;
      expected = null;
    }
    try {
      block();
    } catch (e) {
      actual = e;
    }
    message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
              (message ? ' ' + message : '.');
    if (shouldThrow && !actual) {
      return this._test(false, message, 'Missing expected exception');
    }
    if (!shouldThrow && this._expectedException(actual, expected)) {
      return this._test(false, message, 'Got unwanted exception');
    }
    if ((shouldThrow && actual && expected &&
        !this._expectedException(actual, expected)) || (!shouldThrow && actual)) {
      throw actual;
    }
    return this._test(true, message);
  }
function Expect__throws ( shouldThrow , block , expected , message ) { var actual ; if ( typeof expected === 'string' ) { message = expected ; expected = null ; } try { block ( ) ; } catch ( e ) { actual = e ; } message = ( expected && expected . name ? ' (' + expected . name + ').' : '.' ) + ( message ? ' ' + message : '.' ) ; if ( shouldThrow && ! actual ) { return this . _test ( false , message , 'Missing expected exception' ) ; } if ( ! shouldThrow && this . _expectedException ( actual , expected ) ) { return this . _test ( false , message , 'Got unwanted exception' ) ; } if ( ( shouldThrow && actual && expected && ! this . _expectedException ( actual , expected ) ) || ( ! shouldThrow && actual ) ) { throw actual ; } return this . _test ( true , message ) ; }
Tests whether a code block throws the expected exception
class.
Tests whether a code block throws the expected exception class .