Add assert.ifError

This commit is contained in:
Mikeal Rogers
2010-05-21 12:05:55 -07:00
committed by Ryan Dahl
parent 2b34363d03
commit fe3d8f2411
3 changed files with 7 additions and 0 deletions

View File

@@ -2546,6 +2546,9 @@ Expects `block` to throw an error.
Expects `block` not to throw an error.
### assert.ifError(value)
Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, `error` in callbacks.
## Path

View File

@@ -284,3 +284,4 @@ assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
_throws.apply(this, [false].concat(pSlice.call(arguments)));
};
assert.ifError = function (err) { if (err) {throw err;}};

View File

@@ -154,3 +154,6 @@ try {
}
assert.equal(true,threw,'a.doesNotThrow is not catching type matching errors');
assert.throws(function () {assert.ifError(new Error('test error'))});
assert.doesNotThrow(function(){assert.ifError(null)});
assert.doesNotThrow(function(){assert.ifError()});