Comparing version 4.1.0 to 5.0.0
@@ -276,3 +276,3 @@ 'use strict'; | ||
const compare = this._flags.shallow ? (a, b) => a === b | ||
: (a, b) => Hoek.deepEqual(a, b, settings); | ||
: (a, b) => Hoek.deepEqual(a, b, settings); | ||
@@ -403,6 +403,56 @@ return this.assert(compare(this._ref, value), `equal specified value: ${internals.display(value)}`, this._ref, value); | ||
internals.reject = async function (/* type, message */) { | ||
try { | ||
internals.assert(this, internals.isPromise(this._ref), 'Can only assert reject on promises'); | ||
const type = arguments.length && typeof arguments[0] !== 'string' && !(arguments[0] instanceof RegExp) ? arguments[0] : null; | ||
const lastArg = arguments[1] || arguments[0]; | ||
const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null; | ||
let thrown; | ||
try { | ||
await this._ref; | ||
} | ||
catch (err) { | ||
thrown = err; | ||
} | ||
internals.assert(this, !this._flags.not || !arguments.length, 'Cannot specify arguments when expecting not to reject'); | ||
if (thrown) { | ||
if (type) { | ||
this.assert(thrown instanceof type, 'reject with ' + (type.name || 'provided type')); | ||
} | ||
if (message !== null) { | ||
const error = thrown.message || ''; | ||
this.assert(typeof message === 'string' ? error === message : error.match(message), 'reject with an error with specified message', error, message); | ||
} | ||
this.assert(thrown, 'reject with an error', thrown); | ||
} | ||
return this.assert(thrown, 'reject with an error'); | ||
} | ||
catch (err) { | ||
return new Promise((resolve, reject) => { | ||
reject(err); | ||
}); | ||
} | ||
}; | ||
internals.addMethod(['reject', 'rejects'], internals.reject); | ||
internals.isPromise = function (promise) { | ||
return promise && typeof promise.then === 'function'; | ||
}; | ||
internals.display = function (value) { | ||
const string = value instanceof Error ? `[${value.toString()}]` : | ||
NodeUtil.inspect(value); | ||
const string = value instanceof Error ? `[${value.toString()}]` : (internals.isPromise(value) ? '[Promise]' : NodeUtil.inspect(value)); | ||
@@ -429,2 +479,3 @@ if (!exports.settings.truncateMessages || string.length <= 40) { | ||
'[object Array]': 'array', | ||
'[object AsyncFunction]': 'function', | ||
'[object Date]': 'date', | ||
@@ -431,0 +482,0 @@ '[object Function]': 'function', |
{ | ||
"name": "code", | ||
"description": "assertion library", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"repository": "git://github.com/hapijs/code", | ||
@@ -13,3 +13,3 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=8.0.0" | ||
}, | ||
@@ -20,3 +20,3 @@ "dependencies": { | ||
"devDependencies": { | ||
"lab": "13.x.x", | ||
"lab": "14.x.x", | ||
"markdown-toc": "1.1.x" | ||
@@ -23,0 +23,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
18818
337