core-assert
Advanced tools
Comparing version 0.1.3 to 0.2.0
34
index.js
@@ -1,2 +0,2 @@ | ||
// https://github.com/nodejs/node/blob/ded4f91eeff478a22e4a0eb5ba2c7ce811512c64/lib/assert.js | ||
// https://github.com/nodejs/node/commit/c1d82ac2ff15594840e2a1b9531b506ae067ed27 | ||
// ------------------- // | ||
@@ -46,2 +46,3 @@ | ||
var compare = require('buf-compare'); | ||
var isError = require('is-error'); | ||
// ------------------- // | ||
@@ -308,2 +309,12 @@ | ||
function _tryBlock(block) { | ||
var error; | ||
try { | ||
block(); | ||
} catch (e) { | ||
error = e; | ||
} | ||
return error; | ||
} | ||
function _throws(shouldThrow, block, expected, message) { | ||
@@ -321,7 +332,3 @@ var actual; | ||
try { | ||
block(); | ||
} catch (e) { | ||
actual = e; | ||
} | ||
actual = _tryBlock(block); | ||
@@ -335,3 +342,10 @@ message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + | ||
if (!shouldThrow && expectedException(actual, expected)) { | ||
var userProvidedMessage = typeof message === 'string'; | ||
var isUnwantedException = !shouldThrow && isError(actual); | ||
var isUnexpectedException = !shouldThrow && actual && !expected; | ||
if ((isUnwantedException && | ||
userProvidedMessage && | ||
expectedException(actual, expected)) || | ||
isUnexpectedException) { | ||
fail(actual, expected, 'Got unwanted exception' + message); | ||
@@ -350,8 +364,8 @@ } | ||
assert.throws = function(block, /*optional*/error, /*optional*/message) { | ||
_throws.apply(this, [true].concat(pSlice.call(arguments))); | ||
_throws(true, block, error, message); | ||
}; | ||
// EXTENSION! This is annoying to write outside this module. | ||
assert.doesNotThrow = function(block, /*optional*/message) { | ||
_throws.apply(this, [false].concat(pSlice.call(arguments))); | ||
assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { | ||
_throws(false, block, error, message); | ||
}; | ||
@@ -358,0 +372,0 @@ |
{ | ||
"name": "core-assert", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "Node.js `assert` as a standalone module", | ||
@@ -39,4 +39,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"buf-compare": "^1.0.0" | ||
"buf-compare": "^1.0.0", | ||
"is-error": "^2.2.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14981
308
2
+ Addedis-error@^2.2.0
+ Addedis-error@2.2.2(transitive)