Comparing version 0.8.1 to 0.8.2
@@ -364,7 +364,11 @@ // Load modules | ||
exports.assert = function (condition, message) { | ||
exports.assert = function (condition /*, msg1, msg2, msg3 */) { | ||
if (!condition) { | ||
throw new Error(message || 'Unknown error'); | ||
if (condition) { | ||
return; | ||
} | ||
var msgs = Array.prototype.slice.call(arguments, 1); | ||
msgs = msgs.map(function (msg) { return typeof msg === 'string' ? msg : JSON.stringify(msg); }); | ||
throw new Error(msgs.join(' ') || 'Unknown error'); | ||
}; | ||
@@ -371,0 +375,0 @@ |
{ | ||
"name": "hoek", | ||
"description": "General purpose node utilities", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "contributors":[ |
@@ -46,3 +46,3 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a> | ||
The *Hoek* general purpose node utilities library is used to aid in a variety of manners. It comes with useful methods for Ararys (clone, merge, applyToDefaults), Objects (removeKeys, copy), Asserting and more. | ||
The *Hoek* general purpose node utilities library is used to aid in a variety of manners. It comes with useful methods for Arrays (clone, merge, applyToDefaults), Objects (removeKeys, copy), Asserting and more. | ||
@@ -109,3 +109,3 @@ For example, to use Hoek to set configuration with default options: | ||
newTarget = Hoek.merge(target, source2); // results in {a: null, b: 2, c: 5} | ||
newTarget = Hoek.merge(target, source2, false); // results in {a: null, b:2, c: 5} | ||
newTarget = Hoek.merge(target, source2, false); // results in {a: 1, b: 2, c: 5} | ||
@@ -112,0 +112,0 @@ newTarget = Hoek.merge(targetArray, sourceArray) // results in [1, 2, 3, 4, 5] |
@@ -713,2 +713,35 @@ // Load modules | ||
}); | ||
it('should throw an Error when using assert in a test with no message', function (done) { | ||
var fn = function () { | ||
Hoek.assert(false); | ||
}; | ||
expect(fn).to.throw('Unknown error'); | ||
done(); | ||
}); | ||
it('should throw an Error when using assert in a test with multipart message', function (done) { | ||
var fn = function () { | ||
Hoek.assert(false, 'This', 'is', 'my message'); | ||
}; | ||
expect(fn).to.throw('This is my message'); | ||
done(); | ||
}); | ||
it('should throw an Error when using assert in a test with object message', function (done) { | ||
var fn = function () { | ||
Hoek.assert(false, 'This', 'is', { spinal: 'tap' }); | ||
}; | ||
expect(fn).to.throw('This is {"spinal":"tap"}'); | ||
done(); | ||
}); | ||
}); | ||
@@ -715,0 +748,0 @@ |
Sorry, the diff of this file is not supported yet
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
99190
1281