Browse Source

Add assert.ifError

v0.7.4-release
Mikeal Rogers 15 years ago
committed by Ryan Dahl
parent
commit
fe3d8f2411
  1. 3
      doc/api.markdown
  2. 1
      lib/assert.js
  3. 3
      test/simple/test-assert.js

3
doc/api.markdown

@ -2546,6 +2546,9 @@ Expects `block` to throw an error.
Expects `block` not 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 ## Path

1
lib/assert.js

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

3
test/simple/test-assert.js

@ -154,3 +154,6 @@ try {
} }
assert.equal(true,threw,'a.doesNotThrow is not catching type matching errors'); 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()});

Loading…
Cancel
Save