|
@ -239,47 +239,50 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
function _throws (shouldThrow, block, err, message) { |
|
|
function expectedException(actual, expected) { |
|
|
var exception = null, |
|
|
if (!actual || !expected) { |
|
|
threw = false, |
|
|
return false; |
|
|
typematters = true; |
|
|
} |
|
|
|
|
|
|
|
|
message = message || ""; |
|
|
if (expected instanceof RegExp) { |
|
|
|
|
|
if (expected.test(actual)) { |
|
|
//handle optional arguments
|
|
|
return true; |
|
|
if (arguments.length == 3) { |
|
|
|
|
|
if (typeof(err) == "string") { |
|
|
|
|
|
message = err; |
|
|
|
|
|
typematters = false; |
|
|
|
|
|
} |
|
|
} |
|
|
} else if (arguments.length == 2) { |
|
|
} else if (actual instanceof expected || expected.call({}, actual) !== false) { |
|
|
typematters = false; |
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _throws (shouldThrow, block, expected, message) { |
|
|
|
|
|
var actual; |
|
|
|
|
|
|
|
|
|
|
|
if (typeof expected === "string") { |
|
|
|
|
|
message = expected; |
|
|
|
|
|
expected = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
block(); |
|
|
block(); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
threw = true; |
|
|
actual = e; |
|
|
exception = e; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (shouldThrow && !threw) { |
|
|
message = (expected && expected.name ? " (" + expected.name + ")." : ".") |
|
|
fail( "Missing expected exception" |
|
|
+ (message ? " " + message : "."); |
|
|
+ (err && err.name ? " ("+err.name+")." : '.') |
|
|
|
|
|
+ (message ? " " + message : "") |
|
|
if (shouldThrow && !actual) { |
|
|
); |
|
|
fail("Missing expected exception" + message); |
|
|
} |
|
|
} |
|
|
if (!shouldThrow && threw && typematters && exception instanceof err) { |
|
|
|
|
|
fail( "Got unwanted exception" |
|
|
if (!shouldThrow && expectedException(actual, expected)) { |
|
|
+ (err && err.name ? " ("+err.name+")." : '.') |
|
|
fail("Got unwanted exception" + message); |
|
|
+ (message ? " " + message : "") |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
if ((shouldThrow && threw && typematters && !(exception instanceof err)) || |
|
|
|
|
|
(!shouldThrow && threw)) { |
|
|
if ((shouldThrow && actual && expected && !expectedException(actual, expected)) || |
|
|
throw exception; |
|
|
(!shouldThrow && actual)) { |
|
|
|
|
|
throw actual; |
|
|
} |
|
|
} |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
// 11. Expected to throw an error:
|
|
|
// 11. Expected to throw an error:
|
|
|
// assert.throws(block, Error_opt, message_opt);
|
|
|
// assert.throws(block, Error_opt, message_opt);
|
|
|