From 65c3053f60f9bd96e65aba5390994c2e95b80b26 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:41:17 +0000 Subject: [PATCH] chore: introduce prettier and run it Adds prettier and a `format` script, and includes the results of the initial run. --- .prettierrc.json | 10 + lib/chai.js | 2 +- lib/chai/assertion.js | 58 +- lib/chai/config.js | 2 - lib/chai/core/assertions.js | 1073 +++++++++++--------- lib/chai/interface/assert.js | 622 +++++++----- lib/chai/interface/expect.js | 18 +- lib/chai/interface/should.js | 46 +- lib/chai/utils/addChainableMethod.js | 133 ++- lib/chai/utils/addLengthGuard.js | 23 +- lib/chai/utils/addMethod.js | 3 +- lib/chai/utils/addProperty.js | 55 +- lib/chai/utils/expectTypes.js | 22 +- lib/chai/utils/getMessage.js | 26 +- lib/chai/utils/index.js | 4 +- lib/chai/utils/inspect.js | 4 +- lib/chai/utils/isProxyEnabled.js | 6 +- lib/chai/utils/objDisplay.js | 13 +- lib/chai/utils/overwriteChainableMethod.js | 19 +- lib/chai/utils/overwriteMethod.js | 9 +- lib/chai/utils/overwriteProperty.js | 77 +- lib/chai/utils/proxify.js | 42 +- lib/chai/utils/test.js | 4 +- lib/chai/utils/transferFlags.js | 9 +- lib/chai/utils/type-detect.js | 2 +- package-lock.json | 19 +- package.json | 8 +- 27 files changed, 1330 insertions(+), 979 deletions(-) create mode 100644 .prettierrc.json diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..fba42606 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,10 @@ +{ + "bracketSpacing": false, + "printWidth": 80, + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false, + "arrowParens": "always" +} diff --git a/lib/chai.js b/lib/chai.js index 734e3725..19186896 100644 --- a/lib/chai.js +++ b/lib/chai.js @@ -45,7 +45,7 @@ export function use(fn) { } return exports; -}; +} // Utility Functions export {util}; diff --git a/lib/chai/assertion.js b/lib/chai/assertion.js index 7cc17cda..2969d3e9 100644 --- a/lib/chai/assertion.js +++ b/lib/chai/assertion.js @@ -49,7 +49,7 @@ import * as util from './utils/index.js'; * @returns {unknown} * @private */ -export function Assertion (obj, msg, ssfi, lockSsfi) { +export function Assertion(obj, msg, ssfi, lockSsfi) { util.flag(this, 'ssfi', ssfi || Assertion); util.flag(this, 'lockSsfi', lockSsfi); util.flag(this, 'object', obj); @@ -60,23 +60,31 @@ export function Assertion (obj, msg, ssfi, lockSsfi) { } Object.defineProperty(Assertion, 'includeStack', { - get: function() { - console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.'); + get: function () { + console.warn( + 'Assertion.includeStack is deprecated, use chai.config.includeStack instead.' + ); return config.includeStack; }, - set: function(value) { - console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.'); + set: function (value) { + console.warn( + 'Assertion.includeStack is deprecated, use chai.config.includeStack instead.' + ); config.includeStack = value; } }); Object.defineProperty(Assertion, 'showDiff', { - get: function() { - console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.'); + get: function () { + console.warn( + 'Assertion.showDiff is deprecated, use chai.config.showDiff instead.' + ); return config.showDiff; }, - set: function(value) { - console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.'); + set: function (value) { + console.warn( + 'Assertion.showDiff is deprecated, use chai.config.showDiff instead.' + ); config.showDiff = value; } }); @@ -120,7 +128,14 @@ Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) { * @private */ -Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) { +Assertion.prototype.assert = function ( + expr, + msg, + negateMsg, + expected, + _actual, + showDiff +) { var ok = util.test(this, arguments); if (false !== showDiff) showDiff = true; if (undefined === expected && undefined === _actual) showDiff = false; @@ -130,9 +145,9 @@ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, msg = util.getMessage(this, arguments); var actual = util.getActual(this, arguments); var assertionErrorObjectProperties = { - actual: actual - , expected: expected - , showDiff: showDiff + actual: actual, + expected: expected, + showDiff: showDiff }; var operator = util.getOperator(this, arguments); @@ -143,7 +158,8 @@ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, throw new AssertionError( msg, assertionErrorObjectProperties, - (config.includeStack) ? this.assert : util.flag(this, 'ssfi')); + config.includeStack ? this.assert : util.flag(this, 'ssfi') + ); } }; @@ -154,11 +170,11 @@ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, * * @private */ -Object.defineProperty(Assertion.prototype, '_obj', - { get: function () { - return util.flag(this, 'object'); - } - , set: function (val) { - util.flag(this, 'object', val); - } +Object.defineProperty(Assertion.prototype, '_obj', { + get: function () { + return util.flag(this, 'object'); + }, + set: function (val) { + util.flag(this, 'object', val); + } }); diff --git a/lib/chai/config.js b/lib/chai/config.js index afeae596..07a1bbee 100644 --- a/lib/chai/config.js +++ b/lib/chai/config.js @@ -1,5 +1,4 @@ export const config = { - /** * ### config.includeStack * @@ -110,5 +109,4 @@ export const config = { * @public */ deepEqual: null - }; diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index e2971726..f18da8a9 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -42,10 +42,25 @@ const {flag} = _; * @public */ -[ 'to', 'be', 'been', 'is' -, 'and', 'has', 'have', 'with' -, 'that', 'which', 'at', 'of' -, 'same', 'but', 'does', 'still', "also" ].forEach(function (chain) { +[ + 'to', + 'be', + 'been', + 'is', + 'and', + 'has', + 'have', + 'with', + 'that', + 'which', + 'at', + 'of', + 'same', + 'but', + 'does', + 'still', + 'also' +].forEach(function (chain) { Assertion.addProperty(chain); }); @@ -239,11 +254,16 @@ Assertion.addProperty('all', function () { }); const functionTypes = { - 'function': ['function', 'asyncfunction', 'generatorfunction', 'asyncgeneratorfunction'], - 'asyncfunction': ['asyncfunction', 'asyncgeneratorfunction'], - 'generatorfunction': ['generatorfunction', 'asyncgeneratorfunction'], - 'asyncgeneratorfunction': ['asyncgeneratorfunction'] -} + function: [ + 'function', + 'asyncfunction', + 'generatorfunction', + 'asyncgeneratorfunction' + ], + asyncfunction: ['asyncfunction', 'asyncgeneratorfunction'], + generatorfunction: ['generatorfunction', 'asyncgeneratorfunction'], + asyncgeneratorfunction: ['asyncgeneratorfunction'] +}; /** * ### .a(type[, msg]) @@ -304,25 +324,25 @@ const functionTypes = { * @namespace BDD * @public */ -function an (type, msg) { +function an(type, msg) { if (msg) flag(this, 'message', msg); type = type.toLowerCase(); - var obj = flag(this, 'object') - , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a '; + var obj = flag(this, 'object'), + article = ~['a', 'e', 'i', 'o', 'u'].indexOf(type.charAt(0)) ? 'an ' : 'a '; const detectedType = _.type(obj).toLowerCase(); if (functionTypes['function'].includes(type)) { this.assert( - functionTypes[type].includes(detectedType) - , 'expected #{this} to be ' + article + type - , 'expected #{this} not to be ' + article + type + functionTypes[type].includes(detectedType), + 'expected #{this} to be ' + article + type, + 'expected #{this} not to be ' + article + type ); } else { this.assert( - type === detectedType - , 'expected #{this} to be ' + article + type - , 'expected #{this} not to be ' + article + type + type === detectedType, + 'expected #{this} to be ' + article + type, + 'expected #{this} not to be ' + article + type ); } } @@ -343,7 +363,7 @@ function SameValueZero(a, b) { /** * */ -function includeChainingBehavior () { +function includeChainingBehavior() { flag(this, 'contains', true); } @@ -493,17 +513,17 @@ function includeChainingBehavior () { * @namespace BDD * @public */ -function include (val, msg) { +function include(val, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , objType = _.type(obj).toLowerCase() - , flagMsg = flag(this, 'message') - , negate = flag(this, 'negate') - , ssfi = flag(this, 'ssfi') - , isDeep = flag(this, 'deep') - , descriptor = isDeep ? 'deep ' : '' - , isEql = isDeep ? flag(this, 'eql') : SameValueZero; + var obj = flag(this, 'object'), + objType = _.type(obj).toLowerCase(), + flagMsg = flag(this, 'message'), + negate = flag(this, 'negate'), + ssfi = flag(this, 'ssfi'), + isDeep = flag(this, 'deep'), + descriptor = isDeep ? 'deep ' : '', + isEql = isDeep ? flag(this, 'eql') : SameValueZero; flagMsg = flagMsg ? flagMsg + ': ' : ''; @@ -546,7 +566,7 @@ function include (val, msg) { if (isDeep) { included = obj.some(function (item) { return isEql(item, val); - }) + }); } else { included = obj.indexOf(val) !== -1; } @@ -558,21 +578,24 @@ function include (val, msg) { // objects with a custom `@@toStringTag`. if (val !== Object(val)) { throw new AssertionError( - flagMsg + 'the given combination of arguments (' - + objType + ' and ' - + _.type(val).toLowerCase() + ')' - + ' is invalid for this assertion. ' - + 'You can use an array, a map, an object, a set, a string, ' - + 'or a weakset instead of a ' - + _.type(val).toLowerCase(), + flagMsg + + 'the given combination of arguments (' + + objType + + ' and ' + + _.type(val).toLowerCase() + + ')' + + ' is invalid for this assertion. ' + + 'You can use an array, a map, an object, a set, a string, ' + + 'or a weakset instead of a ' + + _.type(val).toLowerCase(), undefined, ssfi ); } - var props = Object.keys(val) - , firstErr = null - , numErrs = 0; + var props = Object.keys(val), + firstErr = null, + numErrs = 0; props.forEach(function (prop) { var propAssertion = new Assertion(obj); @@ -607,9 +630,10 @@ function include (val, msg) { // Assert inclusion in collection or substring in a string. this.assert( - included - , 'expected #{this} to ' + descriptor + 'include ' + _.inspect(val) - , 'expected #{this} to not ' + descriptor + 'include ' + _.inspect(val)); + included, + 'expected #{this} to ' + descriptor + 'include ' + _.inspect(val), + 'expected #{this} to not ' + descriptor + 'include ' + _.inspect(val) + ); } Assertion.addChainableMethod('include', include, includeChainingBehavior); @@ -654,9 +678,10 @@ Assertion.addChainableMethod('includes', include, includeChainingBehavior); */ Assertion.addProperty('ok', function () { this.assert( - flag(this, 'object') - , 'expected #{this} to be truthy' - , 'expected #{this} to be falsy'); + flag(this, 'object'), + 'expected #{this} to be truthy', + 'expected #{this} to be falsy' + ); }); /** @@ -686,10 +711,10 @@ Assertion.addProperty('ok', function () { */ Assertion.addProperty('true', function () { this.assert( - true === flag(this, 'object') - , 'expected #{this} to be true' - , 'expected #{this} to be false' - , flag(this, 'negate') ? false : true + true === flag(this, 'object'), + 'expected #{this} to be true', + 'expected #{this} to be false', + flag(this, 'negate') ? false : true ); }); @@ -697,10 +722,10 @@ Assertion.addProperty('numeric', function () { const object = flag(this, 'object'); this.assert( - ['Number', 'BigInt'].includes(_.type(object)) - , 'expected #{this} to be numeric' - , 'expected #{this} to not be numeric' - , flag(this, 'negate') ? false : true + ['Number', 'BigInt'].includes(_.type(object)), + 'expected #{this} to be numeric', + 'expected #{this} to not be numeric', + flag(this, 'negate') ? false : true ); }); @@ -720,24 +745,25 @@ Assertion.addProperty('numeric', function () { * @public */ Assertion.addProperty('callable', function () { - const val = flag(this, 'object') - const ssfi = flag(this, 'ssfi') - const message = flag(this, 'message') - const msg = message ? `${message}: ` : '' + const val = flag(this, 'object'); + const ssfi = flag(this, 'ssfi'); + const message = flag(this, 'message'); + const msg = message ? `${message}: ` : ''; const negate = flag(this, 'negate'); - const assertionMessage = negate ? - `${msg}expected ${_.inspect(val)} not to be a callable function` : - `${msg}expected ${_.inspect(val)} to be a callable function`; + const assertionMessage = negate + ? `${msg}expected ${_.inspect(val)} not to be a callable function` + : `${msg}expected ${_.inspect(val)} to be a callable function`; - const isCallable = ['Function', 'AsyncFunction', 'GeneratorFunction', 'AsyncGeneratorFunction'].includes(_.type(val)); + const isCallable = [ + 'Function', + 'AsyncFunction', + 'GeneratorFunction', + 'AsyncGeneratorFunction' + ].includes(_.type(val)); if ((isCallable && negate) || (!isCallable && !negate)) { - throw new AssertionError( - assertionMessage, - undefined, - ssfi - ); + throw new AssertionError(assertionMessage, undefined, ssfi); } }); @@ -768,10 +794,10 @@ Assertion.addProperty('callable', function () { */ Assertion.addProperty('false', function () { this.assert( - false === flag(this, 'object') - , 'expected #{this} to be false' - , 'expected #{this} to be true' - , flag(this, 'negate') ? true : false + false === flag(this, 'object'), + 'expected #{this} to be false', + 'expected #{this} to be true', + flag(this, 'negate') ? true : false ); }); @@ -799,9 +825,9 @@ Assertion.addProperty('false', function () { */ Assertion.addProperty('null', function () { this.assert( - null === flag(this, 'object') - , 'expected #{this} to be null' - , 'expected #{this} not to be null' + null === flag(this, 'object'), + 'expected #{this} to be null', + 'expected #{this} not to be null' ); }); @@ -829,9 +855,9 @@ Assertion.addProperty('null', function () { */ Assertion.addProperty('undefined', function () { this.assert( - undefined === flag(this, 'object') - , 'expected #{this} to be undefined' - , 'expected #{this} not to be undefined' + undefined === flag(this, 'object'), + 'expected #{this} to be undefined', + 'expected #{this} not to be undefined' ); }); @@ -859,9 +885,9 @@ Assertion.addProperty('undefined', function () { */ Assertion.addProperty('NaN', function () { this.assert( - _.isNaN(flag(this, 'object')) - , 'expected #{this} to be NaN' - , 'expected #{this} not to be NaN' + _.isNaN(flag(this, 'object')), + 'expected #{this} to be NaN', + 'expected #{this} not to be NaN' ); }); @@ -897,12 +923,12 @@ Assertion.addProperty('NaN', function () { * @namespace BDD * @public */ -function assertExist () { +function assertExist() { var val = flag(this, 'object'); this.assert( - val !== null && val !== undefined - , 'expected #{this} to exist' - , 'expected #{this} to not exist' + val !== null && val !== undefined, + 'expected #{this} to exist', + 'expected #{this} to not exist' ); } @@ -958,10 +984,10 @@ Assertion.addProperty('exists', assertExist); * @public */ Assertion.addProperty('empty', function () { - var val = flag(this, 'object') - , ssfi = flag(this, 'ssfi') - , flagMsg = flag(this, 'message') - , itemsCount; + var val = flag(this, 'object'), + ssfi = flag(this, 'ssfi'), + flagMsg = flag(this, 'message'), + itemsCount; flagMsg = flagMsg ? flagMsg + ': ' : ''; @@ -996,9 +1022,9 @@ Assertion.addProperty('empty', function () { } this.assert( - 0 === itemsCount - , 'expected #{this} to be empty' - , 'expected #{this} not to be empty' + 0 === itemsCount, + 'expected #{this} to be empty', + 'expected #{this} not to be empty' ); }); @@ -1031,13 +1057,13 @@ Assertion.addProperty('empty', function () { * @namespace BDD * @public */ -function checkArguments () { - var obj = flag(this, 'object') - , type = _.type(obj); +function checkArguments() { + var obj = flag(this, 'object'), + type = _.type(obj); this.assert( - 'Arguments' === type - , 'expected #{this} to be arguments but got ' + type - , 'expected #{this} to not be arguments' + 'Arguments' === type, + 'expected #{this} to be arguments but got ' + type, + 'expected #{this} to not be arguments' ); } @@ -1088,7 +1114,7 @@ Assertion.addProperty('Arguments', checkArguments); * @namespace BDD * @public */ -function assertEqual (val, msg) { +function assertEqual(val, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); if (flag(this, 'deep')) { @@ -1098,12 +1124,12 @@ function assertEqual (val, msg) { flag(this, 'lockSsfi', prevLockSsfi); } else { this.assert( - val === obj - , 'expected #{this} to equal #{exp}' - , 'expected #{this} to not equal #{exp}' - , val - , this._obj - , true + val === obj, + 'expected #{this} to equal #{exp}', + 'expected #{this} to not equal #{exp}', + val, + this._obj, + true ); } } @@ -1156,12 +1182,12 @@ function assertEql(obj, msg) { if (msg) flag(this, 'message', msg); var eql = flag(this, 'eql'); this.assert( - eql(obj, flag(this, 'object')) - , 'expected #{this} to deeply equal #{exp}' - , 'expected #{this} to not deeply equal #{exp}' - , obj - , this._obj - , true + eql(obj, flag(this, 'object')), + 'expected #{this} to deeply equal #{exp}', + 'expected #{this} to not deeply equal #{exp}', + obj, + this._obj, + true ); } @@ -1210,32 +1236,44 @@ Assertion.addMethod('eqls', assertEql); * @namespace BDD * @public */ -function assertAbove (n, msg) { +function assertAbove(n, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , doLength = flag(this, 'doLength') - , flagMsg = flag(this, 'message') - , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '') - , ssfi = flag(this, 'ssfi') - , objType = _.type(obj).toLowerCase() - , nType = _.type(n).toLowerCase(); + var obj = flag(this, 'object'), + doLength = flag(this, 'doLength'), + flagMsg = flag(this, 'message'), + msgPrefix = flagMsg ? flagMsg + ': ' : '', + ssfi = flag(this, 'ssfi'), + objType = _.type(obj).toLowerCase(), + nType = _.type(n).toLowerCase(); if (doLength && objType !== 'map' && objType !== 'set') { new Assertion(obj, flagMsg, ssfi, true).to.have.property('length'); } - if (!doLength && (objType === 'date' && nType !== 'date')) { - throw new AssertionError(msgPrefix + 'the argument to above must be a date', undefined, ssfi); + if (!doLength && objType === 'date' && nType !== 'date') { + throw new AssertionError( + msgPrefix + 'the argument to above must be a date', + undefined, + ssfi + ); } else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) { - throw new AssertionError(msgPrefix + 'the argument to above must be a number', undefined, ssfi); - } else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) { - var printObj = (objType === 'string') ? "'" + obj + "'" : obj; - throw new AssertionError(msgPrefix + 'expected ' + printObj + ' to be a number or a date', undefined, ssfi); + throw new AssertionError( + msgPrefix + 'the argument to above must be a number', + undefined, + ssfi + ); + } else if (!doLength && objType !== 'date' && !_.isNumeric(obj)) { + var printObj = objType === 'string' ? "'" + obj + "'" : obj; + throw new AssertionError( + msgPrefix + 'expected ' + printObj + ' to be a number or a date', + undefined, + ssfi + ); } if (doLength) { - var descriptor = 'length' - , itemsCount; + var descriptor = 'length', + itemsCount; if (objType === 'map' || objType === 'set') { descriptor = 'size'; itemsCount = obj.size; @@ -1243,18 +1281,20 @@ function assertAbove (n, msg) { itemsCount = obj.length; } this.assert( - itemsCount > n - , 'expected #{this} to have a ' + descriptor + ' above #{exp} but got #{act}' - , 'expected #{this} to not have a ' + descriptor + ' above #{exp}' - , n - , itemsCount + itemsCount > n, + 'expected #{this} to have a ' + + descriptor + + ' above #{exp} but got #{act}', + 'expected #{this} to not have a ' + descriptor + ' above #{exp}', + n, + itemsCount ); } else { this.assert( - obj > n - , 'expected #{this} to be above #{exp}' - , 'expected #{this} to be at most #{exp}' - , n + obj > n, + 'expected #{this} to be above #{exp}', + 'expected #{this} to be at most #{exp}', + n ); } } @@ -1306,29 +1346,30 @@ Assertion.addMethod('greaterThan', assertAbove); * @namespace BDD * @public */ -function assertLeast (n, msg) { +function assertLeast(n, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , doLength = flag(this, 'doLength') - , flagMsg = flag(this, 'message') - , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '') - , ssfi = flag(this, 'ssfi') - , objType = _.type(obj).toLowerCase() - , nType = _.type(n).toLowerCase() - , errorMessage - , shouldThrow = true; + var obj = flag(this, 'object'), + doLength = flag(this, 'doLength'), + flagMsg = flag(this, 'message'), + msgPrefix = flagMsg ? flagMsg + ': ' : '', + ssfi = flag(this, 'ssfi'), + objType = _.type(obj).toLowerCase(), + nType = _.type(n).toLowerCase(), + errorMessage, + shouldThrow = true; if (doLength && objType !== 'map' && objType !== 'set') { new Assertion(obj, flagMsg, ssfi, true).to.have.property('length'); } - if (!doLength && (objType === 'date' && nType !== 'date')) { + if (!doLength && objType === 'date' && nType !== 'date') { errorMessage = msgPrefix + 'the argument to least must be a date'; } else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) { errorMessage = msgPrefix + 'the argument to least must be a number'; - } else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) { - var printObj = (objType === 'string') ? "'" + obj + "'" : obj; - errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date'; + } else if (!doLength && objType !== 'date' && !_.isNumeric(obj)) { + var printObj = objType === 'string' ? "'" + obj + "'" : obj; + errorMessage = + msgPrefix + 'expected ' + printObj + ' to be a number or a date'; } else { shouldThrow = false; } @@ -1338,8 +1379,8 @@ function assertLeast (n, msg) { } if (doLength) { - var descriptor = 'length' - , itemsCount; + var descriptor = 'length', + itemsCount; if (objType === 'map' || objType === 'set') { descriptor = 'size'; itemsCount = obj.size; @@ -1347,18 +1388,20 @@ function assertLeast (n, msg) { itemsCount = obj.length; } this.assert( - itemsCount >= n - , 'expected #{this} to have a ' + descriptor + ' at least #{exp} but got #{act}' - , 'expected #{this} to have a ' + descriptor + ' below #{exp}' - , n - , itemsCount + itemsCount >= n, + 'expected #{this} to have a ' + + descriptor + + ' at least #{exp} but got #{act}', + 'expected #{this} to have a ' + descriptor + ' below #{exp}', + n, + itemsCount ); } else { this.assert( - obj >= n - , 'expected #{this} to be at least #{exp}' - , 'expected #{this} to be below #{exp}' - , n + obj >= n, + 'expected #{this} to be at least #{exp}', + 'expected #{this} to be below #{exp}', + n ); } } @@ -1409,29 +1452,30 @@ Assertion.addMethod('greaterThanOrEqual', assertLeast); * @namespace BDD * @public */ -function assertBelow (n, msg) { +function assertBelow(n, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , doLength = flag(this, 'doLength') - , flagMsg = flag(this, 'message') - , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '') - , ssfi = flag(this, 'ssfi') - , objType = _.type(obj).toLowerCase() - , nType = _.type(n).toLowerCase() - , errorMessage - , shouldThrow = true; + var obj = flag(this, 'object'), + doLength = flag(this, 'doLength'), + flagMsg = flag(this, 'message'), + msgPrefix = flagMsg ? flagMsg + ': ' : '', + ssfi = flag(this, 'ssfi'), + objType = _.type(obj).toLowerCase(), + nType = _.type(n).toLowerCase(), + errorMessage, + shouldThrow = true; if (doLength && objType !== 'map' && objType !== 'set') { new Assertion(obj, flagMsg, ssfi, true).to.have.property('length'); } - - if (!doLength && (objType === 'date' && nType !== 'date')) { + + if (!doLength && objType === 'date' && nType !== 'date') { errorMessage = msgPrefix + 'the argument to below must be a date'; } else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) { errorMessage = msgPrefix + 'the argument to below must be a number'; - } else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) { - var printObj = (objType === 'string') ? "'" + obj + "'" : obj; - errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date'; + } else if (!doLength && objType !== 'date' && !_.isNumeric(obj)) { + var printObj = objType === 'string' ? "'" + obj + "'" : obj; + errorMessage = + msgPrefix + 'expected ' + printObj + ' to be a number or a date'; } else { shouldThrow = false; } @@ -1441,8 +1485,8 @@ function assertBelow (n, msg) { } if (doLength) { - var descriptor = 'length' - , itemsCount; + var descriptor = 'length', + itemsCount; if (objType === 'map' || objType === 'set') { descriptor = 'size'; itemsCount = obj.size; @@ -1450,18 +1494,20 @@ function assertBelow (n, msg) { itemsCount = obj.length; } this.assert( - itemsCount < n - , 'expected #{this} to have a ' + descriptor + ' below #{exp} but got #{act}' - , 'expected #{this} to not have a ' + descriptor + ' below #{exp}' - , n - , itemsCount + itemsCount < n, + 'expected #{this} to have a ' + + descriptor + + ' below #{exp} but got #{act}', + 'expected #{this} to not have a ' + descriptor + ' below #{exp}', + n, + itemsCount ); } else { this.assert( - obj < n - , 'expected #{this} to be below #{exp}' - , 'expected #{this} to be at least #{exp}' - , n + obj < n, + 'expected #{this} to be below #{exp}', + 'expected #{this} to be at least #{exp}', + n ); } } @@ -1513,29 +1559,30 @@ Assertion.addMethod('lessThan', assertBelow); * @namespace BDD * @public */ -function assertMost (n, msg) { +function assertMost(n, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , doLength = flag(this, 'doLength') - , flagMsg = flag(this, 'message') - , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '') - , ssfi = flag(this, 'ssfi') - , objType = _.type(obj).toLowerCase() - , nType = _.type(n).toLowerCase() - , errorMessage - , shouldThrow = true; + var obj = flag(this, 'object'), + doLength = flag(this, 'doLength'), + flagMsg = flag(this, 'message'), + msgPrefix = flagMsg ? flagMsg + ': ' : '', + ssfi = flag(this, 'ssfi'), + objType = _.type(obj).toLowerCase(), + nType = _.type(n).toLowerCase(), + errorMessage, + shouldThrow = true; if (doLength && objType !== 'map' && objType !== 'set') { new Assertion(obj, flagMsg, ssfi, true).to.have.property('length'); } - if (!doLength && (objType === 'date' && nType !== 'date')) { + if (!doLength && objType === 'date' && nType !== 'date') { errorMessage = msgPrefix + 'the argument to most must be a date'; } else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) { errorMessage = msgPrefix + 'the argument to most must be a number'; - } else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) { - var printObj = (objType === 'string') ? "'" + obj + "'" : obj; - errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date'; + } else if (!doLength && objType !== 'date' && !_.isNumeric(obj)) { + var printObj = objType === 'string' ? "'" + obj + "'" : obj; + errorMessage = + msgPrefix + 'expected ' + printObj + ' to be a number or a date'; } else { shouldThrow = false; } @@ -1545,8 +1592,8 @@ function assertMost (n, msg) { } if (doLength) { - var descriptor = 'length' - , itemsCount; + var descriptor = 'length', + itemsCount; if (objType === 'map' || objType === 'set') { descriptor = 'size'; itemsCount = obj.size; @@ -1554,18 +1601,20 @@ function assertMost (n, msg) { itemsCount = obj.length; } this.assert( - itemsCount <= n - , 'expected #{this} to have a ' + descriptor + ' at most #{exp} but got #{act}' - , 'expected #{this} to have a ' + descriptor + ' above #{exp}' - , n - , itemsCount + itemsCount <= n, + 'expected #{this} to have a ' + + descriptor + + ' at most #{exp} but got #{act}', + 'expected #{this} to have a ' + descriptor + ' above #{exp}', + n, + itemsCount ); } else { this.assert( - obj <= n - , 'expected #{this} to be at most #{exp}' - , 'expected #{this} to be above #{exp}' - , n + obj <= n, + 'expected #{this} to be at most #{exp}', + 'expected #{this} to be above #{exp}', + n ); } } @@ -1618,17 +1667,18 @@ Assertion.addMethod('lessThanOrEqual', assertMost); */ Assertion.addMethod('within', function (start, finish, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , doLength = flag(this, 'doLength') - , flagMsg = flag(this, 'message') - , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '') - , ssfi = flag(this, 'ssfi') - , objType = _.type(obj).toLowerCase() - , startType = _.type(start).toLowerCase() - , finishType = _.type(finish).toLowerCase() - , errorMessage - , shouldThrow = true - , range = (startType === 'date' && finishType === 'date') + var obj = flag(this, 'object'), + doLength = flag(this, 'doLength'), + flagMsg = flag(this, 'message'), + msgPrefix = flagMsg ? flagMsg + ': ' : '', + ssfi = flag(this, 'ssfi'), + objType = _.type(obj).toLowerCase(), + startType = _.type(start).toLowerCase(), + finishType = _.type(finish).toLowerCase(), + errorMessage, + shouldThrow = true, + range = + startType === 'date' && finishType === 'date' ? start.toISOString() + '..' + finish.toISOString() : start + '..' + finish; @@ -1636,13 +1686,21 @@ Assertion.addMethod('within', function (start, finish, msg) { new Assertion(obj, flagMsg, ssfi, true).to.have.property('length'); } - if (!doLength && (objType === 'date' && (startType !== 'date' || finishType !== 'date'))) { + if ( + !doLength && + objType === 'date' && + (startType !== 'date' || finishType !== 'date') + ) { errorMessage = msgPrefix + 'the arguments to within must be dates'; - } else if ((!_.isNumeric(start) || !_.isNumeric(finish)) && (doLength || _.isNumeric(obj))) { + } else if ( + (!_.isNumeric(start) || !_.isNumeric(finish)) && + (doLength || _.isNumeric(obj)) + ) { errorMessage = msgPrefix + 'the arguments to within must be numbers'; - } else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) { - var printObj = (objType === 'string') ? "'" + obj + "'" : obj; - errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date'; + } else if (!doLength && objType !== 'date' && !_.isNumeric(obj)) { + var printObj = objType === 'string' ? "'" + obj + "'" : obj; + errorMessage = + msgPrefix + 'expected ' + printObj + ' to be a number or a date'; } else { shouldThrow = false; } @@ -1652,8 +1710,8 @@ Assertion.addMethod('within', function (start, finish, msg) { } if (doLength) { - var descriptor = 'length' - , itemsCount; + var descriptor = 'length', + itemsCount; if (objType === 'map' || objType === 'set') { descriptor = 'size'; itemsCount = obj.size; @@ -1661,15 +1719,15 @@ Assertion.addMethod('within', function (start, finish, msg) { itemsCount = obj.length; } this.assert( - itemsCount >= start && itemsCount <= finish - , 'expected #{this} to have a ' + descriptor + ' within ' + range - , 'expected #{this} to not have a ' + descriptor + ' within ' + range + itemsCount >= start && itemsCount <= finish, + 'expected #{this} to have a ' + descriptor + ' within ' + range, + 'expected #{this} to not have a ' + descriptor + ' within ' + range ); } else { this.assert( - obj >= start && obj <= finish - , 'expected #{this} to be within ' + range - , 'expected #{this} to not be within ' + range + obj >= start && obj <= finish, + 'expected #{this} to be within ' + range, + 'expected #{this} to not be within ' + range ); } }); @@ -1712,10 +1770,10 @@ Assertion.addMethod('within', function (start, finish, msg) { * @namespace BDD * @public */ -function assertInstanceOf (constructor, msg) { +function assertInstanceOf(constructor, msg) { if (msg) flag(this, 'message', msg); - var target = flag(this, 'object') + var target = flag(this, 'object'); var ssfi = flag(this, 'ssfi'); var flagMsg = flag(this, 'message'); @@ -1725,8 +1783,10 @@ function assertInstanceOf (constructor, msg) { if (err instanceof TypeError) { flagMsg = flagMsg ? flagMsg + ': ' : ''; throw new AssertionError( - flagMsg + 'The instanceof assertion needs a constructor but ' - + _.type(constructor) + ' was given.', + flagMsg + + 'The instanceof assertion needs a constructor but ' + + _.type(constructor) + + ' was given.', undefined, ssfi ); @@ -1740,11 +1800,11 @@ function assertInstanceOf (constructor, msg) { } this.assert( - isInstanceOf - , 'expected #{this} to be an instance of ' + name - , 'expected #{this} to not be an instance of ' + name + isInstanceOf, + 'expected #{this} to be an instance of ' + name, + 'expected #{this} to not be an instance of ' + name ); -}; +} Assertion.addMethod('instanceof', assertInstanceOf); Assertion.addMethod('instanceOf', assertInstanceOf); @@ -1859,30 +1919,36 @@ Assertion.addMethod('instanceOf', assertInstanceOf); * @namespace BDD * @public */ -function assertProperty (name, val, msg) { +function assertProperty(name, val, msg) { if (msg) flag(this, 'message', msg); - var isNested = flag(this, 'nested') - , isOwn = flag(this, 'own') - , flagMsg = flag(this, 'message') - , obj = flag(this, 'object') - , ssfi = flag(this, 'ssfi') - , nameType = typeof name; + var isNested = flag(this, 'nested'), + isOwn = flag(this, 'own'), + flagMsg = flag(this, 'message'), + obj = flag(this, 'object'), + ssfi = flag(this, 'ssfi'), + nameType = typeof name; flagMsg = flagMsg ? flagMsg + ': ' : ''; if (isNested) { if (nameType !== 'string') { throw new AssertionError( - flagMsg + 'the argument to property must be a string when using nested syntax', + flagMsg + + 'the argument to property must be a string when using nested syntax', undefined, ssfi ); } } else { - if (nameType !== 'string' && nameType !== 'number' && nameType !== 'symbol') { + if ( + nameType !== 'string' && + nameType !== 'number' && + nameType !== 'symbol' + ) { throw new AssertionError( - flagMsg + 'the argument to property must be a string, number, or symbol', + flagMsg + + 'the argument to property must be a string, number, or symbol', undefined, ssfi ); @@ -1905,11 +1971,11 @@ function assertProperty (name, val, msg) { ); } - var isDeep = flag(this, 'deep') - , negate = flag(this, 'negate') - , pathInfo = isNested ? _.getPathInfo(obj, name) : null - , value = isNested ? pathInfo.value : obj[name] - , isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2; + var isDeep = flag(this, 'deep'), + negate = flag(this, 'negate'), + pathInfo = isNested ? _.getPathInfo(obj, name) : null, + value = isNested ? pathInfo.value : obj[name], + isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2; var descriptor = ''; if (isDeep) descriptor += 'deep '; @@ -1929,18 +1995,25 @@ function assertProperty (name, val, msg) { // favor of the next. if (!negate || arguments.length === 1) { this.assert( - hasProperty - , 'expected #{this} to have ' + descriptor + _.inspect(name) - , 'expected #{this} to not have ' + descriptor + _.inspect(name)); + hasProperty, + 'expected #{this} to have ' + descriptor + _.inspect(name), + 'expected #{this} to not have ' + descriptor + _.inspect(name) + ); } if (arguments.length > 1) { this.assert( - hasProperty && isEql(val, value) - , 'expected #{this} to have ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}' - , 'expected #{this} to not have ' + descriptor + _.inspect(name) + ' of #{act}' - , val - , value + hasProperty && isEql(val, value), + 'expected #{this} to have ' + + descriptor + + _.inspect(name) + + ' of #{exp}, but got #{act}', + 'expected #{this} to not have ' + + descriptor + + _.inspect(name) + + ' of #{act}', + val, + value ); } @@ -1955,7 +2028,7 @@ Assertion.addMethod('property', assertProperty); * @param {unknown} value * @param {string} msg */ -function assertOwnProperty (name, value, msg) { +function assertOwnProperty(name, value, msg) { flag(this, 'own', true); assertProperty.apply(this, arguments); } @@ -2081,7 +2154,7 @@ Assertion.addMethod('haveOwnProperty', assertOwnProperty); * @namespace BDD * @public */ -function assertOwnPropertyDescriptor (name, descriptor, msg) { +function assertOwnPropertyDescriptor(name, descriptor, msg) { if (typeof descriptor === 'string') { msg = descriptor; descriptor = null; @@ -2092,18 +2165,28 @@ function assertOwnPropertyDescriptor (name, descriptor, msg) { var eql = flag(this, 'eql'); if (actualDescriptor && descriptor) { this.assert( - eql(descriptor, actualDescriptor) - , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor) - , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor) - , descriptor - , actualDescriptor - , true + eql(descriptor, actualDescriptor), + 'expected the own property descriptor for ' + + _.inspect(name) + + ' on #{this} to match ' + + _.inspect(descriptor) + + ', got ' + + _.inspect(actualDescriptor), + 'expected the own property descriptor for ' + + _.inspect(name) + + ' on #{this} to not match ' + + _.inspect(descriptor), + descriptor, + actualDescriptor, + true ); } else { this.assert( - actualDescriptor - , 'expected #{this} to have an own property descriptor for ' + _.inspect(name) - , 'expected #{this} to not have an own property descriptor for ' + _.inspect(name) + actualDescriptor, + 'expected #{this} to have an own property descriptor for ' + + _.inspect(name), + 'expected #{this} to not have an own property descriptor for ' + + _.inspect(name) ); } flag(this, 'object', actualDescriptor); @@ -2115,7 +2198,7 @@ Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor); /** * */ -function assertLengthChain () { +function assertLengthChain() { flag(this, 'doLength', true); } @@ -2176,14 +2259,14 @@ function assertLengthChain () { * @namespace BDD * @public */ -function assertLength (n, msg) { +function assertLength(n, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , objType = _.type(obj).toLowerCase() - , flagMsg = flag(this, 'message') - , ssfi = flag(this, 'ssfi') - , descriptor = 'length' - , itemsCount; + var obj = flag(this, 'object'), + objType = _.type(obj).toLowerCase(), + flagMsg = flag(this, 'message'), + ssfi = flag(this, 'ssfi'), + descriptor = 'length', + itemsCount; switch (objType) { case 'map': @@ -2197,11 +2280,11 @@ function assertLength (n, msg) { } this.assert( - itemsCount == n - , 'expected #{this} to have a ' + descriptor + ' of #{exp} but got #{act}' - , 'expected #{this} to not have a ' + descriptor + ' of #{act}' - , n - , itemsCount + itemsCount == n, + 'expected #{this} to have a ' + descriptor + ' of #{exp} but got #{act}', + 'expected #{this} to not have a ' + descriptor + ' of #{act}', + n, + itemsCount ); } @@ -2239,9 +2322,9 @@ function assertMatch(re, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); this.assert( - re.exec(obj) - , 'expected #{this} to match ' + re - , 'expected #{this} not to match ' + re + re.exec(obj), + 'expected #{this} to match ' + re, + 'expected #{this} not to match ' + re ); } @@ -2274,15 +2357,15 @@ Assertion.addMethod('matches', assertMatch); */ Assertion.addMethod('string', function (str, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , flagMsg = flag(this, 'message') - , ssfi = flag(this, 'ssfi'); + var obj = flag(this, 'object'), + flagMsg = flag(this, 'message'), + ssfi = flag(this, 'ssfi'); new Assertion(obj, flagMsg, ssfi, true).is.a('string'); this.assert( - ~obj.indexOf(str) - , 'expected #{this} to contain ' + _.inspect(str) - , 'expected #{this} to not contain ' + _.inspect(str) + ~obj.indexOf(str), + 'expected #{this} to contain ' + _.inspect(str), + 'expected #{this} to not contain ' + _.inspect(str) ); }); @@ -2389,27 +2472,31 @@ Assertion.addMethod('string', function (str, msg) { * @namespace BDD * @public */ -function assertKeys (keys) { - var obj = flag(this, 'object') - , objType = _.type(obj) - , keysType = _.type(keys) - , ssfi = flag(this, 'ssfi') - , isDeep = flag(this, 'deep') - , str - , deepStr = '' - , actual - , ok = true - , flagMsg = flag(this, 'message'); +function assertKeys(keys) { + var obj = flag(this, 'object'), + objType = _.type(obj), + keysType = _.type(keys), + ssfi = flag(this, 'ssfi'), + isDeep = flag(this, 'deep'), + str, + deepStr = '', + actual, + ok = true, + flagMsg = flag(this, 'message'); flagMsg = flagMsg ? flagMsg + ': ' : ''; - var mixedArgsMsg = flagMsg + 'when testing keys against an object or an array you must give a single Array|Object|String argument or multiple String arguments'; + var mixedArgsMsg = + flagMsg + + 'when testing keys against an object or an array you must give a single Array|Object|String argument or multiple String arguments'; if (objType === 'Map' || objType === 'Set') { deepStr = isDeep ? 'deeply ' : ''; actual = []; // Map and Set '.keys' aren't supported in IE 11. Therefore, use .forEach. - obj.forEach(function (val, key) { actual.push(key) }); + obj.forEach(function (val, key) { + actual.push(key); + }); if (keysType !== 'Array') { keys = Array.prototype.slice.call(arguments); @@ -2443,11 +2530,11 @@ function assertKeys (keys) { throw new AssertionError(flagMsg + 'keys required', undefined, ssfi); } - var len = keys.length - , any = flag(this, 'any') - , all = flag(this, 'all') - , expected = keys - , isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2; + var len = keys.length, + any = flag(this, 'any'), + all = flag(this, 'all'), + expected = keys, + isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2; if (!any && !all) { all = true; @@ -2455,8 +2542,8 @@ function assertKeys (keys) { // Has any if (any) { - ok = expected.some(function(expectedKey) { - return actual.some(function(actualKey) { + ok = expected.some(function (expectedKey) { + return actual.some(function (actualKey) { return isEql(expectedKey, actualKey); }); }); @@ -2464,8 +2551,8 @@ function assertKeys (keys) { // Has all if (all) { - ok = expected.every(function(expectedKey) { - return actual.some(function(actualKey) { + ok = expected.every(function (expectedKey) { + return actual.some(function (actualKey) { return isEql(expectedKey, actualKey); }); }); @@ -2477,7 +2564,7 @@ function assertKeys (keys) { // Key string if (len > 1) { - keys = keys.map(function(key) { + keys = keys.map(function (key) { return _.inspect(key); }); var last = keys.pop(); @@ -2499,12 +2586,12 @@ function assertKeys (keys) { // Assertion this.assert( - ok - , 'expected #{this} to ' + deepStr + str - , 'expected #{this} to not ' + deepStr + str - , expected.slice(0).sort(_.compareByInspect) - , actual.sort(_.compareByInspect) - , true + ok, + 'expected #{this} to ' + deepStr + str, + 'expected #{this} to not ' + deepStr + str, + expected.slice(0).sort(_.compareByInspect), + actual.sort(_.compareByInspect), + true ); } @@ -2670,12 +2757,12 @@ Assertion.addMethod('key', assertKeys); * @namespace BDD * @public */ -function assertThrows (errorLike, errMsgMatcher, msg) { +function assertThrows(errorLike, errMsgMatcher, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , ssfi = flag(this, 'ssfi') - , flagMsg = flag(this, 'message') - , negate = flag(this, 'negate') || false; + var obj = flag(this, 'object'), + ssfi = flag(this, 'ssfi'), + flagMsg = flag(this, 'message'), + negate = flag(this, 'negate') || false; new Assertion(obj, flagMsg, ssfi, true).is.a('function'); if (_.isRegExp(errorLike) || typeof errorLike === 'string') { @@ -2694,7 +2781,8 @@ function assertThrows (errorLike, errMsgMatcher, msg) { // If we have the negate flag enabled and at least one valid argument it means we do expect an error // but we want it to match a given set of criteria - var everyArgIsUndefined = errorLike === undefined && errMsgMatcher === undefined; + var everyArgIsUndefined = + errorLike === undefined && errMsgMatcher === undefined; // If we've got the negate flag enabled and both args, we should only fail if both aren't compatible // See Issue #551 and PR #683@GitHub @@ -2703,7 +2791,7 @@ function assertThrows (errorLike, errMsgMatcher, msg) { var errMsgMatcherFail = false; // Checking if error was thrown - if (everyArgIsUndefined || !everyArgIsUndefined && !negate) { + if (everyArgIsUndefined || (!everyArgIsUndefined && !negate)) { // We need this to display results correctly according to their types var errorLikeString = 'an error'; if (errorLike instanceof Error) { @@ -2717,7 +2805,10 @@ function assertThrows (errorLike, errMsgMatcher, msg) { actual = caughtErr.toString(); } else if (typeof caughtErr === 'string') { actual = caughtErr; - } else if (caughtErr && (typeof caughtErr === 'object' || typeof caughtErr === 'function')) { + } else if ( + caughtErr && + (typeof caughtErr === 'object' || typeof caughtErr === 'function') + ) { try { actual = _.checkError.getConstructorName(caughtErr); } catch (_err) { @@ -2727,18 +2818,21 @@ function assertThrows (errorLike, errMsgMatcher, msg) { } this.assert( - errorWasThrown - , 'expected #{this} to throw ' + errorLikeString - , 'expected #{this} to not throw an error but #{act} was thrown' - , errorLike && errorLike.toString() - , actual + errorWasThrown, + 'expected #{this} to throw ' + errorLikeString, + 'expected #{this} to not throw an error but #{act} was thrown', + errorLike && errorLike.toString(), + actual ); } if (errorLike && caughtErr) { // We should compare instances only if `errorLike` is an instance of `Error` if (errorLike instanceof Error) { - var isCompatibleInstance = _.checkError.compatibleInstance(caughtErr, errorLike); + var isCompatibleInstance = _.checkError.compatibleInstance( + caughtErr, + errorLike + ); if (isCompatibleInstance === negate) { // These checks were created to ensure we won't fail too soon when we've got both args and a negate @@ -2747,27 +2841,36 @@ function assertThrows (errorLike, errMsgMatcher, msg) { errorLikeFail = true; } else { this.assert( - negate - , 'expected #{this} to throw #{exp} but #{act} was thrown' - , 'expected #{this} to not throw #{exp}' + (caughtErr && !negate ? ' but #{act} was thrown' : '') - , errorLike.toString() - , caughtErr.toString() + negate, + 'expected #{this} to throw #{exp} but #{act} was thrown', + 'expected #{this} to not throw #{exp}' + + (caughtErr && !negate ? ' but #{act} was thrown' : ''), + errorLike.toString(), + caughtErr.toString() ); } } } - var isCompatibleConstructor = _.checkError.compatibleConstructor(caughtErr, errorLike); + var isCompatibleConstructor = _.checkError.compatibleConstructor( + caughtErr, + errorLike + ); if (isCompatibleConstructor === negate) { if (everyArgIsDefined && negate) { - errorLikeFail = true; + errorLikeFail = true; } else { this.assert( - negate - , 'expected #{this} to throw #{exp} but #{act} was thrown' - , 'expected #{this} to not throw #{exp}' + (caughtErr ? ' but #{act} was thrown' : '') - , (errorLike instanceof Error ? errorLike.toString() : errorLike && _.checkError.getConstructorName(errorLike)) - , (caughtErr instanceof Error ? caughtErr.toString() : caughtErr && _.checkError.getConstructorName(caughtErr)) + negate, + 'expected #{this} to throw #{exp} but #{act} was thrown', + 'expected #{this} to not throw #{exp}' + + (caughtErr ? ' but #{act} was thrown' : ''), + errorLike instanceof Error + ? errorLike.toString() + : errorLike && _.checkError.getConstructorName(errorLike), + caughtErr instanceof Error + ? caughtErr.toString() + : caughtErr && _.checkError.getConstructorName(caughtErr) ); } } @@ -2777,20 +2880,25 @@ function assertThrows (errorLike, errMsgMatcher, msg) { // Here we check compatible messages var placeholder = 'including'; if (_.isRegExp(errMsgMatcher)) { - placeholder = 'matching' + placeholder = 'matching'; } - var isCompatibleMessage = _.checkError.compatibleMessage(caughtErr, errMsgMatcher); + var isCompatibleMessage = _.checkError.compatibleMessage( + caughtErr, + errMsgMatcher + ); if (isCompatibleMessage === negate) { if (everyArgIsDefined && negate) { - errMsgMatcherFail = true; + errMsgMatcherFail = true; } else { this.assert( - negate - , 'expected #{this} to throw error ' + placeholder + ' #{exp} but got #{act}' - , 'expected #{this} to throw error not ' + placeholder + ' #{exp}' - , errMsgMatcher - , _.checkError.getMessage(caughtErr) + negate, + 'expected #{this} to throw error ' + + placeholder + + ' #{exp} but got #{act}', + 'expected #{this} to throw error not ' + placeholder + ' #{exp}', + errMsgMatcher, + _.checkError.getMessage(caughtErr) ); } } @@ -2799,16 +2907,21 @@ function assertThrows (errorLike, errMsgMatcher, msg) { // If both assertions failed and both should've matched we throw an error if (errorLikeFail && errMsgMatcherFail) { this.assert( - negate - , 'expected #{this} to throw #{exp} but #{act} was thrown' - , 'expected #{this} to not throw #{exp}' + (caughtErr ? ' but #{act} was thrown' : '') - , (errorLike instanceof Error ? errorLike.toString() : errorLike && _.checkError.getConstructorName(errorLike)) - , (caughtErr instanceof Error ? caughtErr.toString() : caughtErr && _.checkError.getConstructorName(caughtErr)) + negate, + 'expected #{this} to throw #{exp} but #{act} was thrown', + 'expected #{this} to not throw #{exp}' + + (caughtErr ? ' but #{act} was thrown' : ''), + errorLike instanceof Error + ? errorLike.toString() + : errorLike && _.checkError.getConstructorName(errorLike), + caughtErr instanceof Error + ? caughtErr.toString() + : caughtErr && _.checkError.getConstructorName(caughtErr) ); } flag(this, 'object', caughtErr); -}; +} Assertion.addMethod('throw', assertThrows); Assertion.addMethod('throws', assertThrows); @@ -2878,18 +2991,19 @@ Assertion.addMethod('Throw', assertThrows); * @namespace BDD * @public */ -function respondTo (method, msg) { +function respondTo(method, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , itself = flag(this, 'itself') - , context = ('function' === typeof obj && !itself) - ? obj.prototype[method] - : obj[method]; + var obj = flag(this, 'object'), + itself = flag(this, 'itself'), + context = + 'function' === typeof obj && !itself + ? obj.prototype[method] + : obj[method]; this.assert( - 'function' === typeof context - , 'expected #{this} to respond to ' + _.inspect(method) - , 'expected #{this} to not respond to ' + _.inspect(method) + 'function' === typeof context, + 'expected #{this} to respond to ' + _.inspect(method), + 'expected #{this} to not respond to ' + _.inspect(method) ); } @@ -2956,16 +3070,16 @@ Assertion.addProperty('itself', function () { * @namespace BDD * @public */ -function satisfy (matcher, msg) { +function satisfy(matcher, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); var result = matcher(obj); this.assert( - result - , 'expected #{this} to satisfy ' + _.objDisplay(matcher) - , 'expected #{this} to not satisfy' + _.objDisplay(matcher) - , flag(this, 'negate') ? false : true - , result + result, + 'expected #{this} to satisfy ' + _.objDisplay(matcher), + 'expected #{this} to not satisfy' + _.objDisplay(matcher), + flag(this, 'negate') ? false : true, + result ); } @@ -3011,24 +3125,34 @@ Assertion.addMethod('satisfies', satisfy); */ function closeTo(expected, delta, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , flagMsg = flag(this, 'message') - , ssfi = flag(this, 'ssfi'); + var obj = flag(this, 'object'), + flagMsg = flag(this, 'message'), + ssfi = flag(this, 'ssfi'); new Assertion(obj, flagMsg, ssfi, true).is.numeric; - let message = 'A `delta` value is required for `closeTo`'; - if (delta == undefined) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi); + let message = 'A `delta` value is required for `closeTo`'; + if (delta == undefined) + throw new AssertionError( + flagMsg ? `${flagMsg}: ${message}` : message, + undefined, + ssfi + ); new Assertion(delta, flagMsg, ssfi, true).is.numeric; - message = 'A `expected` value is required for `closeTo`'; - if (expected == undefined) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi); + message = 'A `expected` value is required for `closeTo`'; + if (expected == undefined) + throw new AssertionError( + flagMsg ? `${flagMsg}: ${message}` : message, + undefined, + ssfi + ); new Assertion(expected, flagMsg, ssfi, true).is.numeric; - const abs = (x) => x < 0n ? -x : x; + const abs = (x) => (x < 0n ? -x : x); this.assert( - abs(obj - expected) <= delta - , 'expected #{this} to be close to ' + expected + ' +/- ' + delta - , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta + abs(obj - expected) <= delta, + 'expected #{this} to be close to ' + expected + ' +/- ' + delta, + 'expected #{this} not to be close to ' + expected + ' +/- ' + delta ); } @@ -3051,7 +3175,7 @@ function isSubsetOf(_subset, _superset, cmp, contains, ordered) { superset = superset.slice(); } - return subset.every(function(elem, idx) { + return subset.every(function (elem, idx) { if (ordered) return cmp ? cmp(elem, superset[idx]) : elem === superset[idx]; if (!cmp) { @@ -3063,7 +3187,7 @@ function isSubsetOf(_subset, _superset, cmp, contains, ordered) { return true; } - return superset.some(function(elem2, matchIdx) { + return superset.some(function (elem2, matchIdx) { if (!cmp(elem, elem2)) return false; // Remove match from superset so not counted twice if duplicate in subset. @@ -3143,9 +3267,9 @@ function isSubsetOf(_subset, _superset, cmp, contains, ordered) { */ Assertion.addMethod('members', function (subset, msg) { if (msg) flag(this, 'message', msg); - var obj = flag(this, 'object') - , flagMsg = flag(this, 'message') - , ssfi = flag(this, 'ssfi'); + var obj = flag(this, 'object'), + flagMsg = flag(this, 'message'), + ssfi = flag(this, 'ssfi'); new Assertion(obj, flagMsg, ssfi, true).to.be.iterable; new Assertion(subset, flagMsg, ssfi, true).to.be.iterable; @@ -3162,18 +3286,19 @@ Assertion.addMethod('members', function (subset, msg) { } else { subject = ordered ? 'ordered members' : 'members'; failMsg = 'expected #{this} to have the same ' + subject + ' as #{exp}'; - failNegateMsg = 'expected #{this} to not have the same ' + subject + ' as #{exp}'; + failNegateMsg = + 'expected #{this} to not have the same ' + subject + ' as #{exp}'; } var cmp = flag(this, 'deep') ? flag(this, 'eql') : undefined; this.assert( - isSubsetOf(subset, obj, cmp, contains, ordered) - , failMsg - , failNegateMsg - , subset - , obj - , true + isSubsetOf(subset, obj, cmp, contains, ordered), + failMsg, + failNegateMsg, + subset, + obj, + true ); }); @@ -3198,15 +3323,15 @@ Assertion.addMethod('members', function (subset, msg) { * @namespace BDD * @public */ -Assertion.addProperty('iterable', function(msg) { +Assertion.addProperty('iterable', function (msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); this.assert( - obj != undefined && obj[Symbol.iterator] - , 'expected #{this} to be an iterable' - , 'expected #{this} to not be an iterable' - , obj + obj != undefined && obj[Symbol.iterator], + 'expected #{this} to be an iterable', + 'expected #{this} to not be an iterable', + obj ); }); @@ -3247,40 +3372,44 @@ Assertion.addProperty('iterable', function(msg) { * @namespace BDD * @public */ -function oneOf (list, msg) { +function oneOf(list, msg) { if (msg) flag(this, 'message', msg); - var expected = flag(this, 'object') - , flagMsg = flag(this, 'message') - , ssfi = flag(this, 'ssfi') - , contains = flag(this, 'contains') - , isDeep = flag(this, 'deep') - , eql = flag(this, 'eql'); + var expected = flag(this, 'object'), + flagMsg = flag(this, 'message'), + ssfi = flag(this, 'ssfi'), + contains = flag(this, 'contains'), + isDeep = flag(this, 'deep'), + eql = flag(this, 'eql'); new Assertion(list, flagMsg, ssfi, true).to.be.an('array'); if (contains) { this.assert( - list.some(function(possibility) { return expected.indexOf(possibility) > -1 }) - , 'expected #{this} to contain one of #{exp}' - , 'expected #{this} to not contain one of #{exp}' - , list - , expected + list.some(function (possibility) { + return expected.indexOf(possibility) > -1; + }), + 'expected #{this} to contain one of #{exp}', + 'expected #{this} to not contain one of #{exp}', + list, + expected ); } else { if (isDeep) { this.assert( - list.some(function(possibility) { return eql(expected, possibility) }) - , 'expected #{this} to deeply equal one of #{exp}' - , 'expected #{this} to deeply equal one of #{exp}' - , list - , expected + list.some(function (possibility) { + return eql(expected, possibility); + }), + 'expected #{this} to deeply equal one of #{exp}', + 'expected #{this} to deeply equal one of #{exp}', + list, + expected ); } else { this.assert( - list.indexOf(expected) > -1 - , 'expected #{this} to be one of #{exp}' - , 'expected #{this} to not be one of #{exp}' - , list - , expected + list.indexOf(expected) > -1, + 'expected #{this} to be one of #{exp}', + 'expected #{this} to not be one of #{exp}', + list, + expected ); } } @@ -3382,11 +3511,11 @@ Assertion.addMethod('oneOf', oneOf); * @namespace BDD * @public */ -function assertChanges (subject, prop, msg) { +function assertChanges(subject, prop, msg) { if (msg) flag(this, 'message', msg); - var fn = flag(this, 'object') - , flagMsg = flag(this, 'message') - , ssfi = flag(this, 'ssfi'); + var fn = flag(this, 'object'), + flagMsg = flag(this, 'message'), + ssfi = flag(this, 'ssfi'); new Assertion(fn, flagMsg, ssfi, true).is.a('function'); var initial; @@ -3411,9 +3540,9 @@ function assertChanges (subject, prop, msg) { flag(this, 'realDelta', final !== initial); this.assert( - initial !== final - , 'expected ' + msgObj + ' to change' - , 'expected ' + msgObj + ' to not change' + initial !== final, + 'expected ' + msgObj + ' to change', + 'expected ' + msgObj + ' to not change' ); } @@ -3498,11 +3627,11 @@ Assertion.addMethod('changes', assertChanges); * @namespace BDD * @public */ -function assertIncreases (subject, prop, msg) { +function assertIncreases(subject, prop, msg) { if (msg) flag(this, 'message', msg); - var fn = flag(this, 'object') - , flagMsg = flag(this, 'message') - , ssfi = flag(this, 'ssfi'); + var fn = flag(this, 'object'), + flagMsg = flag(this, 'message'), + ssfi = flag(this, 'ssfi'); new Assertion(fn, flagMsg, ssfi, true).is.a('function'); var initial; @@ -3529,9 +3658,9 @@ function assertIncreases (subject, prop, msg) { flag(this, 'realDelta', final - initial); this.assert( - final - initial > 0 - , 'expected ' + msgObj + ' to increase' - , 'expected ' + msgObj + ' to not increase' + final - initial > 0, + 'expected ' + msgObj + ' to increase', + 'expected ' + msgObj + ' to not increase' ); } @@ -3616,11 +3745,11 @@ Assertion.addMethod('increases', assertIncreases); * @namespace BDD * @public */ -function assertDecreases (subject, prop, msg) { +function assertDecreases(subject, prop, msg) { if (msg) flag(this, 'message', msg); - var fn = flag(this, 'object') - , flagMsg = flag(this, 'message') - , ssfi = flag(this, 'ssfi'); + var fn = flag(this, 'object'), + flagMsg = flag(this, 'message'), + ssfi = flag(this, 'ssfi'); new Assertion(fn, flagMsg, ssfi, true).is.a('function'); var initial; @@ -3647,9 +3776,9 @@ function assertDecreases (subject, prop, msg) { flag(this, 'realDelta', initial - final); this.assert( - final - initial < 0 - , 'expected ' + msgObj + ' to decrease' - , 'expected ' + msgObj + ' to not decrease' + final - initial < 0, + 'expected ' + msgObj + ' to decrease', + 'expected ' + msgObj + ' to not decrease' ); } @@ -3738,9 +3867,9 @@ function assertDelta(delta, msg) { } this.assert( - expression - , 'expected ' + msgObj + ' to ' + behavior + ' by ' + delta - , 'expected ' + msgObj + ' to not ' + behavior + ' by ' + delta + expression, + 'expected ' + msgObj + ' to ' + behavior + ' by ' + delta, + 'expected ' + msgObj + ' to not ' + behavior + ' by ' + delta ); } @@ -3773,7 +3902,7 @@ Assertion.addMethod('by', assertDelta); * @namespace BDD * @public */ -Assertion.addProperty('extensible', function() { +Assertion.addProperty('extensible', function () { var obj = flag(this, 'object'); // In ES5, if the argument to this method is a primitive, then it will cause a TypeError. @@ -3784,9 +3913,9 @@ Assertion.addProperty('extensible', function() { var isExtensible = obj === Object(obj) && Object.isExtensible(obj); this.assert( - isExtensible - , 'expected #{this} to be extensible' - , 'expected #{this} to not be extensible' + isExtensible, + 'expected #{this} to be extensible', + 'expected #{this} to not be extensible' ); }); @@ -3817,7 +3946,7 @@ Assertion.addProperty('extensible', function() { * @namespace BDD * @public */ -Assertion.addProperty('sealed', function() { +Assertion.addProperty('sealed', function () { var obj = flag(this, 'object'); // In ES5, if the argument to this method is a primitive, then it will cause a TypeError. @@ -3828,9 +3957,9 @@ Assertion.addProperty('sealed', function() { var isSealed = obj === Object(obj) ? Object.isSealed(obj) : true; this.assert( - isSealed - , 'expected #{this} to be sealed' - , 'expected #{this} to not be sealed' + isSealed, + 'expected #{this} to be sealed', + 'expected #{this} to not be sealed' ); }); @@ -3858,7 +3987,7 @@ Assertion.addProperty('sealed', function() { * @namespace BDD * @public */ -Assertion.addProperty('frozen', function() { +Assertion.addProperty('frozen', function () { var obj = flag(this, 'object'); // In ES5, if the argument to this method is a primitive, then it will cause a TypeError. @@ -3869,9 +3998,9 @@ Assertion.addProperty('frozen', function() { var isFrozen = obj === Object(obj) ? Object.isFrozen(obj) : true; this.assert( - isFrozen - , 'expected #{this} to be frozen' - , 'expected #{this} to not be frozen' + isFrozen, + 'expected #{this} to be frozen', + 'expected #{this} to not be frozen' ); }); @@ -3923,12 +4052,12 @@ Assertion.addProperty('frozen', function() { * @namespace BDD * @public */ -Assertion.addProperty('finite', function(msg) { +Assertion.addProperty('finite', function (msg) { var obj = flag(this, 'object'); this.assert( - typeof obj === 'number' && isFinite(obj) - , 'expected #{this} to be a finite number' - , 'expected #{this} to not be a finite number' + typeof obj === 'number' && isFinite(obj), + 'expected #{this} to be a finite number', + 'expected #{this} to not be a finite number' ); }); diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 721ec2a3..8f0fa9bc 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -25,11 +25,7 @@ import {AssertionError} from 'assertion-error'; */ export function assert(express, errmsg) { var test = new Assertion(null, null, chai.assert, true); - test.assert( - express - , errmsg - , '[ negation message unavailable ]' - ); + test.assert(express, errmsg, '[ negation message unavailable ]'); } /** @@ -55,18 +51,22 @@ export function assert(express, errmsg) { */ assert.fail = function (actual, expected, message, operator) { if (arguments.length < 2) { - // Comply with Node's fail([message]) interface + // Comply with Node's fail([message]) interface - message = actual; - actual = undefined; + message = actual; + actual = undefined; } message = message || 'assert.fail()'; - throw new AssertionError(message, { - actual: actual - , expected: expected - , operator: operator - }, assert.fail); + throw new AssertionError( + message, + { + actual: actual, + expected: expected, + operator: operator + }, + assert.fail + ); }; /** @@ -125,12 +125,12 @@ assert.equal = function (act, exp, msg) { var test = new Assertion(act, msg, assert.equal, true); test.assert( - exp == flag(test, 'object') - , 'expected #{this} to equal #{exp}' - , 'expected #{this} to not equal #{act}' - , exp - , act - , true + exp == flag(test, 'object'), + 'expected #{this} to equal #{exp}', + 'expected #{this} to not equal #{act}', + exp, + act, + true ); }; @@ -152,12 +152,12 @@ assert.notEqual = function (act, exp, msg) { var test = new Assertion(act, msg, assert.notEqual, true); test.assert( - exp != flag(test, 'object') - , 'expected #{this} to not equal #{exp}' - , 'expected #{this} to equal #{act}' - , exp - , act - , true + exp != flag(test, 'object'), + 'expected #{this} to not equal #{exp}', + 'expected #{this} to equal #{act}', + exp, + act, + true ); }; @@ -540,7 +540,7 @@ assert.isDefined = function (val, msg) { */ assert.isCallable = function (value, message) { new Assertion(value, message, assert.isCallable, true).is.callable; -} +}; /** * ### .isNotCallable(value, [message]) @@ -713,7 +713,7 @@ assert.isNotNumber = function (val, msg) { * * var cups = 2; * assert.isNumeric(cups, 'how many cups'); - * + * * var cups = 10n; * assert.isNumeric(cups, 'how many cups'); * @@ -745,21 +745,21 @@ assert.isNotNumeric = function (val, msg) { new Assertion(val, msg, assert.isNotNumeric, true).is.not.numeric; }; - /** - * ### .isFinite(value, [message]) - * - * Asserts that `value` is a finite number. Unlike `.isNumber`, this will fail for `NaN` and `Infinity`. - * - * var cups = 2; - * assert.isFinite(cups, 'how many cups'); - * assert.isFinite(NaN); // throws - * - * @name isFinite - * @param {number} val - * @param {string} msg - * @namespace Assert - * @public - */ +/** + * ### .isFinite(value, [message]) + * + * Asserts that `value` is a finite number. Unlike `.isNumber`, this will fail for `NaN` and `Infinity`. + * + * var cups = 2; + * assert.isFinite(cups, 'how many cups'); + * assert.isFinite(NaN); // throws + * + * @name isFinite + * @param {number} val + * @param {string} msg + * @namespace Assert + * @public + */ assert.isFinite = function (val, msg) { new Assertion(val, msg, assert.isFinite, true).to.be.finite; }; @@ -888,8 +888,9 @@ assert.instanceOf = function (val, type, msg) { * @public */ assert.notInstanceOf = function (val, type, msg) { - new Assertion(val, msg, assert.notInstanceOf, true) - .to.not.be.instanceOf(type); + new Assertion(val, msg, assert.notInstanceOf, true).to.not.be.instanceOf( + type + ); }; /** @@ -1054,8 +1055,9 @@ assert.nestedInclude = function (exp, inc, msg) { * @public */ assert.notNestedInclude = function (exp, inc, msg) { - new Assertion(exp, msg, assert.notNestedInclude, true) - .not.nested.include(inc); + new Assertion(exp, msg, assert.notNestedInclude, true).not.nested.include( + inc + ); }; /** @@ -1078,9 +1080,10 @@ assert.notNestedInclude = function (exp, inc, msg) { * @namespace Assert * @public */ -assert.deepNestedInclude = function(exp, inc, msg) { - new Assertion(exp, msg, assert.deepNestedInclude, true) - .deep.nested.include(inc); +assert.deepNestedInclude = function (exp, inc, msg) { + new Assertion(exp, msg, assert.deepNestedInclude, true).deep.nested.include( + inc + ); }; /** @@ -1103,9 +1106,13 @@ assert.deepNestedInclude = function(exp, inc, msg) { * @namespace Assert * @public */ -assert.notDeepNestedInclude = function(exp, inc, msg) { - new Assertion(exp, msg, assert.notDeepNestedInclude, true) - .not.deep.nested.include(inc); +assert.notDeepNestedInclude = function (exp, inc, msg) { + new Assertion( + exp, + msg, + assert.notDeepNestedInclude, + true + ).not.deep.nested.include(inc); }; /** @@ -1124,7 +1131,7 @@ assert.notDeepNestedInclude = function(exp, inc, msg) { * @namespace Assert * @public */ -assert.ownInclude = function(exp, inc, msg) { +assert.ownInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.ownInclude, true).own.include(inc); }; @@ -1145,7 +1152,7 @@ assert.ownInclude = function(exp, inc, msg) { * @namespace Assert * @public */ -assert.notOwnInclude = function(exp, inc, msg) { +assert.notOwnInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc); }; @@ -1165,9 +1172,8 @@ assert.notOwnInclude = function(exp, inc, msg) { * @namespace Assert * @public */ -assert.deepOwnInclude = function(exp, inc, msg) { - new Assertion(exp, msg, assert.deepOwnInclude, true) - .deep.own.include(inc); +assert.deepOwnInclude = function (exp, inc, msg) { + new Assertion(exp, msg, assert.deepOwnInclude, true).deep.own.include(inc); }; /** @@ -1186,9 +1192,10 @@ assert.deepOwnInclude = function(exp, inc, msg) { * @namespace Assert * @public */ -assert.notDeepOwnInclude = function(exp, inc, msg) { - new Assertion(exp, msg, assert.notDeepOwnInclude, true) - .not.deep.own.include(inc); +assert.notDeepOwnInclude = function (exp, inc, msg) { + new Assertion(exp, msg, assert.notDeepOwnInclude, true).not.deep.own.include( + inc + ); }; /** @@ -1263,8 +1270,7 @@ assert.property = function (obj, prop, msg) { * @public */ assert.notProperty = function (obj, prop, msg) { - new Assertion(obj, msg, assert.notProperty, true) - .to.not.have.property(prop); + new Assertion(obj, msg, assert.notProperty, true).to.not.have.property(prop); }; /** @@ -1285,8 +1291,7 @@ assert.notProperty = function (obj, prop, msg) { * @public */ assert.propertyVal = function (obj, prop, val, msg) { - new Assertion(obj, msg, assert.propertyVal, true) - .to.have.property(prop, val); + new Assertion(obj, msg, assert.propertyVal, true).to.have.property(prop, val); }; /** @@ -1308,8 +1313,10 @@ assert.propertyVal = function (obj, prop, val, msg) { * @public */ assert.notPropertyVal = function (obj, prop, val, msg) { - new Assertion(obj, msg, assert.notPropertyVal, true) - .to.not.have.property(prop, val); + new Assertion(obj, msg, assert.notPropertyVal, true).to.not.have.property( + prop, + val + ); }; /** @@ -1329,8 +1336,10 @@ assert.notPropertyVal = function (obj, prop, val, msg) { * @public */ assert.deepPropertyVal = function (obj, prop, val, msg) { - new Assertion(obj, msg, assert.deepPropertyVal, true) - .to.have.deep.property(prop, val); + new Assertion(obj, msg, assert.deepPropertyVal, true).to.have.deep.property( + prop, + val + ); }; /** @@ -1352,8 +1361,12 @@ assert.deepPropertyVal = function (obj, prop, val, msg) { * @public */ assert.notDeepPropertyVal = function (obj, prop, val, msg) { - new Assertion(obj, msg, assert.notDeepPropertyVal, true) - .to.not.have.deep.property(prop, val); + new Assertion( + obj, + msg, + assert.notDeepPropertyVal, + true + ).to.not.have.deep.property(prop, val); }; /** @@ -1371,8 +1384,7 @@ assert.notDeepPropertyVal = function (obj, prop, val, msg) { * @public */ assert.ownProperty = function (obj, prop, msg) { - new Assertion(obj, msg, assert.ownProperty, true) - .to.have.own.property(prop); + new Assertion(obj, msg, assert.ownProperty, true).to.have.own.property(prop); }; /** @@ -1391,8 +1403,9 @@ assert.ownProperty = function (obj, prop, msg) { * @public */ assert.notOwnProperty = function (obj, prop, msg) { - new Assertion(obj, msg, assert.notOwnProperty, true) - .to.not.have.own.property(prop); + new Assertion(obj, msg, assert.notOwnProperty, true).to.not.have.own.property( + prop + ); }; /** @@ -1412,8 +1425,10 @@ assert.notOwnProperty = function (obj, prop, msg) { * @public */ assert.ownPropertyVal = function (obj, prop, value, msg) { - new Assertion(obj, msg, assert.ownPropertyVal, true) - .to.have.own.property(prop, value); + new Assertion(obj, msg, assert.ownPropertyVal, true).to.have.own.property( + prop, + value + ); }; /** @@ -1434,8 +1449,12 @@ assert.ownPropertyVal = function (obj, prop, value, msg) { * @public */ assert.notOwnPropertyVal = function (obj, prop, value, msg) { - new Assertion(obj, msg, assert.notOwnPropertyVal, true) - .to.not.have.own.property(prop, value); + new Assertion( + obj, + msg, + assert.notOwnPropertyVal, + true + ).to.not.have.own.property(prop, value); }; /** @@ -1455,8 +1474,12 @@ assert.notOwnPropertyVal = function (obj, prop, value, msg) { * @public */ assert.deepOwnPropertyVal = function (obj, prop, value, msg) { - new Assertion(obj, msg, assert.deepOwnPropertyVal, true) - .to.have.deep.own.property(prop, value); + new Assertion( + obj, + msg, + assert.deepOwnPropertyVal, + true + ).to.have.deep.own.property(prop, value); }; /** @@ -1479,8 +1502,12 @@ assert.deepOwnPropertyVal = function (obj, prop, value, msg) { * @public */ assert.notDeepOwnPropertyVal = function (obj, prop, value, msg) { - new Assertion(obj, msg, assert.notDeepOwnPropertyVal, true) - .to.not.have.deep.own.property(prop, value); + new Assertion( + obj, + msg, + assert.notDeepOwnPropertyVal, + true + ).to.not.have.deep.own.property(prop, value); }; /** @@ -1500,8 +1527,9 @@ assert.notDeepOwnPropertyVal = function (obj, prop, value, msg) { * @public */ assert.nestedProperty = function (obj, prop, msg) { - new Assertion(obj, msg, assert.nestedProperty, true) - .to.have.nested.property(prop); + new Assertion(obj, msg, assert.nestedProperty, true).to.have.nested.property( + prop + ); }; /** @@ -1521,8 +1549,12 @@ assert.nestedProperty = function (obj, prop, msg) { * @public */ assert.notNestedProperty = function (obj, prop, msg) { - new Assertion(obj, msg, assert.notNestedProperty, true) - .to.not.have.nested.property(prop); + new Assertion( + obj, + msg, + assert.notNestedProperty, + true + ).to.not.have.nested.property(prop); }; /** @@ -1543,8 +1575,12 @@ assert.notNestedProperty = function (obj, prop, msg) { * @public */ assert.nestedPropertyVal = function (obj, prop, val, msg) { - new Assertion(obj, msg, assert.nestedPropertyVal, true) - .to.have.nested.property(prop, val); + new Assertion( + obj, + msg, + assert.nestedPropertyVal, + true + ).to.have.nested.property(prop, val); }; /** @@ -1566,8 +1602,12 @@ assert.nestedPropertyVal = function (obj, prop, val, msg) { * @public */ assert.notNestedPropertyVal = function (obj, prop, val, msg) { - new Assertion(obj, msg, assert.notNestedPropertyVal, true) - .to.not.have.nested.property(prop, val); + new Assertion( + obj, + msg, + assert.notNestedPropertyVal, + true + ).to.not.have.nested.property(prop, val); }; /** @@ -1588,8 +1628,12 @@ assert.notNestedPropertyVal = function (obj, prop, val, msg) { * @public */ assert.deepNestedPropertyVal = function (obj, prop, val, msg) { - new Assertion(obj, msg, assert.deepNestedPropertyVal, true) - .to.have.deep.nested.property(prop, val); + new Assertion( + obj, + msg, + assert.deepNestedPropertyVal, + true + ).to.have.deep.nested.property(prop, val); }; /** @@ -1612,9 +1656,13 @@ assert.deepNestedPropertyVal = function (obj, prop, val, msg) { * @public */ assert.notDeepNestedPropertyVal = function (obj, prop, val, msg) { - new Assertion(obj, msg, assert.notDeepNestedPropertyVal, true) - .to.not.have.deep.nested.property(prop, val); -} + new Assertion( + obj, + msg, + assert.notDeepNestedPropertyVal, + true + ).to.not.have.deep.nested.property(prop, val); +}; /** * ### .lengthOf(object, length, [message]) @@ -1658,7 +1706,7 @@ assert.lengthOf = function (exp, len, msg) { */ assert.hasAnyKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.hasAnyKeys, true).to.have.any.keys(keys); -} +}; /** * ### .hasAllKeys(object, [keys], [message]) @@ -1681,7 +1729,7 @@ assert.hasAnyKeys = function (obj, keys, msg) { */ assert.hasAllKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.hasAllKeys, true).to.have.all.keys(keys); -} +}; /** * ### .containsAllKeys(object, [keys], [message]) @@ -1707,9 +1755,10 @@ assert.hasAllKeys = function (obj, keys, msg) { * @public */ assert.containsAllKeys = function (obj, keys, msg) { - new Assertion(obj, msg, assert.containsAllKeys, true) - .to.contain.all.keys(keys); -} + new Assertion(obj, msg, assert.containsAllKeys, true).to.contain.all.keys( + keys + ); +}; /** * ### .doesNotHaveAnyKeys(object, [keys], [message]) @@ -1731,9 +1780,10 @@ assert.containsAllKeys = function (obj, keys, msg) { * @public */ assert.doesNotHaveAnyKeys = function (obj, keys, msg) { - new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true) - .to.not.have.any.keys(keys); -} + new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true).to.not.have.any.keys( + keys + ); +}; /** * ### .doesNotHaveAllKeys(object, [keys], [message]) @@ -1755,9 +1805,10 @@ assert.doesNotHaveAnyKeys = function (obj, keys, msg) { * @public */ assert.doesNotHaveAllKeys = function (obj, keys, msg) { - new Assertion(obj, msg, assert.doesNotHaveAllKeys, true) - .to.not.have.all.keys(keys); -} + new Assertion(obj, msg, assert.doesNotHaveAllKeys, true).to.not.have.all.keys( + keys + ); +}; /** * ### .hasAnyDeepKeys(object, [keys], [message]) @@ -1783,9 +1834,10 @@ assert.doesNotHaveAllKeys = function (obj, keys, msg) { * @public */ assert.hasAnyDeepKeys = function (obj, keys, msg) { - new Assertion(obj, msg, assert.hasAnyDeepKeys, true) - .to.have.any.deep.keys(keys); -} + new Assertion(obj, msg, assert.hasAnyDeepKeys, true).to.have.any.deep.keys( + keys + ); +}; /** * ### .hasAllDeepKeys(object, [keys], [message]) @@ -1809,9 +1861,10 @@ assert.hasAnyDeepKeys = function (obj, keys, msg) { * @public */ assert.hasAllDeepKeys = function (obj, keys, msg) { - new Assertion(obj, msg, assert.hasAllDeepKeys, true) - .to.have.all.deep.keys(keys); -} + new Assertion(obj, msg, assert.hasAllDeepKeys, true).to.have.all.deep.keys( + keys + ); +}; /** * ### .containsAllDeepKeys(object, [keys], [message]) @@ -1835,9 +1888,13 @@ assert.hasAllDeepKeys = function (obj, keys, msg) { * @public */ assert.containsAllDeepKeys = function (obj, keys, msg) { - new Assertion(obj, msg, assert.containsAllDeepKeys, true) - .to.contain.all.deep.keys(keys); -} + new Assertion( + obj, + msg, + assert.containsAllDeepKeys, + true + ).to.contain.all.deep.keys(keys); +}; /** * ### .doesNotHaveAnyDeepKeys(object, [keys], [message]) @@ -1861,9 +1918,13 @@ assert.containsAllDeepKeys = function (obj, keys, msg) { * @public */ assert.doesNotHaveAnyDeepKeys = function (obj, keys, msg) { - new Assertion(obj, msg, assert.doesNotHaveAnyDeepKeys, true) - .to.not.have.any.deep.keys(keys); -} + new Assertion( + obj, + msg, + assert.doesNotHaveAnyDeepKeys, + true + ).to.not.have.any.deep.keys(keys); +}; /** * ### .doesNotHaveAllDeepKeys(object, [keys], [message]) @@ -1887,9 +1948,13 @@ assert.doesNotHaveAnyDeepKeys = function (obj, keys, msg) { * @public */ assert.doesNotHaveAllDeepKeys = function (obj, keys, msg) { - new Assertion(obj, msg, assert.doesNotHaveAllDeepKeys, true) - .to.not.have.all.deep.keys(keys); -} + new Assertion( + obj, + msg, + assert.doesNotHaveAllDeepKeys, + true + ).to.not.have.all.deep.keys(keys); +}; /** * ### .throws(fn, [errorLike/string/regexp], [string/regexp], [message]) @@ -1928,8 +1993,10 @@ assert.throws = function (fn, errorLike, errMsgMatcher, msg) { errorLike = null; } - var assertErr = new Assertion(fn, msg, assert.throws, true) - .to.throw(errorLike, errMsgMatcher); + var assertErr = new Assertion(fn, msg, assert.throws, true).to.throw( + errorLike, + errMsgMatcher + ); return flag(assertErr, 'object'); }; @@ -1967,8 +2034,10 @@ assert.doesNotThrow = function (fn, errorLike, errMsgMatcher, message) { errorLike = null; } - new Assertion(fn, message, assert.doesNotThrow, true) - .to.not.throw(errorLike, errMsgMatcher); + new Assertion(fn, message, assert.doesNotThrow, true).to.not.throw( + errorLike, + errMsgMatcher + ); }; /** @@ -1989,7 +2058,7 @@ assert.doesNotThrow = function (fn, errorLike, errMsgMatcher, message) { */ assert.operator = function (val, operator, val2, msg) { var ok; - switch(operator) { + switch (operator) { case '==': ok = val == val2; break; @@ -2024,9 +2093,10 @@ assert.operator = function (val, operator, val2, msg) { } var test = new Assertion(ok, msg, assert.operator, true); test.assert( - true === flag(test, 'object') - , 'expected ' + inspect(val) + ' to be ' + operator + ' ' + inspect(val2) - , 'expected ' + inspect(val) + ' to not be ' + operator + ' ' + inspect(val2) ); + true === flag(test, 'object'), + 'expected ' + inspect(val) + ' to be ' + operator + ' ' + inspect(val2), + 'expected ' + inspect(val) + ' to not be ' + operator + ' ' + inspect(val2) + ); }; /** @@ -2064,8 +2134,10 @@ assert.closeTo = function (act, exp, delta, msg) { * @public */ assert.approximately = function (act, exp, delta, msg) { - new Assertion(act, msg, assert.approximately, true) - .to.be.approximately(exp, delta); + new Assertion(act, msg, assert.approximately, true).to.be.approximately( + exp, + delta + ); }; /** @@ -2084,9 +2156,8 @@ assert.approximately = function (act, exp, delta, msg) { * @public */ assert.sameMembers = function (set1, set2, msg) { - new Assertion(set1, msg, assert.sameMembers, true) - .to.have.same.members(set2); -} + new Assertion(set1, msg, assert.sameMembers, true).to.have.same.members(set2); +}; /** * ### .notSameMembers(set1, set2, [message]) @@ -2104,9 +2175,13 @@ assert.sameMembers = function (set1, set2, msg) { * @public */ assert.notSameMembers = function (set1, set2, msg) { - new Assertion(set1, msg, assert.notSameMembers, true) - .to.not.have.same.members(set2); -} + new Assertion( + set1, + msg, + assert.notSameMembers, + true + ).to.not.have.same.members(set2); +}; /** * ### .sameDeepMembers(set1, set2, [message]) @@ -2124,9 +2199,13 @@ assert.notSameMembers = function (set1, set2, msg) { * @public */ assert.sameDeepMembers = function (set1, set2, msg) { - new Assertion(set1, msg, assert.sameDeepMembers, true) - .to.have.same.deep.members(set2); -} + new Assertion( + set1, + msg, + assert.sameDeepMembers, + true + ).to.have.same.deep.members(set2); +}; /** * ### .notSameDeepMembers(set1, set2, [message]) @@ -2144,9 +2223,13 @@ assert.sameDeepMembers = function (set1, set2, msg) { * @public */ assert.notSameDeepMembers = function (set1, set2, msg) { - new Assertion(set1, msg, assert.notSameDeepMembers, true) - .to.not.have.same.deep.members(set2); -} + new Assertion( + set1, + msg, + assert.notSameDeepMembers, + true + ).to.not.have.same.deep.members(set2); +}; /** * ### .sameOrderedMembers(set1, set2, [message]) @@ -2164,9 +2247,13 @@ assert.notSameDeepMembers = function (set1, set2, msg) { * @public */ assert.sameOrderedMembers = function (set1, set2, msg) { - new Assertion(set1, msg, assert.sameOrderedMembers, true) - .to.have.same.ordered.members(set2); -} + new Assertion( + set1, + msg, + assert.sameOrderedMembers, + true + ).to.have.same.ordered.members(set2); +}; /** * ### .notSameOrderedMembers(set1, set2, [message]) @@ -2184,9 +2271,13 @@ assert.sameOrderedMembers = function (set1, set2, msg) { * @public */ assert.notSameOrderedMembers = function (set1, set2, msg) { - new Assertion(set1, msg, assert.notSameOrderedMembers, true) - .to.not.have.same.ordered.members(set2); -} + new Assertion( + set1, + msg, + assert.notSameOrderedMembers, + true + ).to.not.have.same.ordered.members(set2); +}; /** * ### .sameDeepOrderedMembers(set1, set2, [message]) @@ -2204,9 +2295,13 @@ assert.notSameOrderedMembers = function (set1, set2, msg) { * @public */ assert.sameDeepOrderedMembers = function (set1, set2, msg) { - new Assertion(set1, msg, assert.sameDeepOrderedMembers, true) - .to.have.same.deep.ordered.members(set2); -} + new Assertion( + set1, + msg, + assert.sameDeepOrderedMembers, + true + ).to.have.same.deep.ordered.members(set2); +}; /** * ### .notSameDeepOrderedMembers(set1, set2, [message]) @@ -2225,9 +2320,13 @@ assert.sameDeepOrderedMembers = function (set1, set2, msg) { * @public */ assert.notSameDeepOrderedMembers = function (set1, set2, msg) { - new Assertion(set1, msg, assert.notSameDeepOrderedMembers, true) - .to.not.have.same.deep.ordered.members(set2); -} + new Assertion( + set1, + msg, + assert.notSameDeepOrderedMembers, + true + ).to.not.have.same.deep.ordered.members(set2); +}; /** * ### .includeMembers(superset, subset, [message]) @@ -2245,9 +2344,10 @@ assert.notSameDeepOrderedMembers = function (set1, set2, msg) { * @public */ assert.includeMembers = function (superset, subset, msg) { - new Assertion(superset, msg, assert.includeMembers, true) - .to.include.members(subset); -} + new Assertion(superset, msg, assert.includeMembers, true).to.include.members( + subset + ); +}; /** * ### .notIncludeMembers(superset, subset, [message]) @@ -2265,9 +2365,13 @@ assert.includeMembers = function (superset, subset, msg) { * @public */ assert.notIncludeMembers = function (superset, subset, msg) { - new Assertion(superset, msg, assert.notIncludeMembers, true) - .to.not.include.members(subset); -} + new Assertion( + superset, + msg, + assert.notIncludeMembers, + true + ).to.not.include.members(subset); +}; /** * ### .includeDeepMembers(superset, subset, [message]) @@ -2285,9 +2389,13 @@ assert.notIncludeMembers = function (superset, subset, msg) { * @public */ assert.includeDeepMembers = function (superset, subset, msg) { - new Assertion(superset, msg, assert.includeDeepMembers, true) - .to.include.deep.members(subset); -} + new Assertion( + superset, + msg, + assert.includeDeepMembers, + true + ).to.include.deep.members(subset); +}; /** * ### .notIncludeDeepMembers(superset, subset, [message]) @@ -2305,9 +2413,13 @@ assert.includeDeepMembers = function (superset, subset, msg) { * @public */ assert.notIncludeDeepMembers = function (superset, subset, msg) { - new Assertion(superset, msg, assert.notIncludeDeepMembers, true) - .to.not.include.deep.members(subset); -} + new Assertion( + superset, + msg, + assert.notIncludeDeepMembers, + true + ).to.not.include.deep.members(subset); +}; /** * ### .includeOrderedMembers(superset, subset, [message]) @@ -2326,9 +2438,13 @@ assert.notIncludeDeepMembers = function (superset, subset, msg) { * @public */ assert.includeOrderedMembers = function (superset, subset, msg) { - new Assertion(superset, msg, assert.includeOrderedMembers, true) - .to.include.ordered.members(subset); -} + new Assertion( + superset, + msg, + assert.includeOrderedMembers, + true + ).to.include.ordered.members(subset); +}; /** * ### .notIncludeOrderedMembers(superset, subset, [message]) @@ -2348,9 +2464,13 @@ assert.includeOrderedMembers = function (superset, subset, msg) { * @public */ assert.notIncludeOrderedMembers = function (superset, subset, msg) { - new Assertion(superset, msg, assert.notIncludeOrderedMembers, true) - .to.not.include.ordered.members(subset); -} + new Assertion( + superset, + msg, + assert.notIncludeOrderedMembers, + true + ).to.not.include.ordered.members(subset); +}; /** * ### .includeDeepOrderedMembers(superset, subset, [message]) @@ -2369,9 +2489,13 @@ assert.notIncludeOrderedMembers = function (superset, subset, msg) { * @public */ assert.includeDeepOrderedMembers = function (superset, subset, msg) { - new Assertion(superset, msg, assert.includeDeepOrderedMembers, true) - .to.include.deep.ordered.members(subset); -} + new Assertion( + superset, + msg, + assert.includeDeepOrderedMembers, + true + ).to.include.deep.ordered.members(subset); +}; /** * ### .notIncludeDeepOrderedMembers(superset, subset, [message]) @@ -2392,9 +2516,13 @@ assert.includeDeepOrderedMembers = function (superset, subset, msg) { * @public */ assert.notIncludeDeepOrderedMembers = function (superset, subset, msg) { - new Assertion(superset, msg, assert.notIncludeDeepOrderedMembers, true) - .to.not.include.deep.ordered.members(subset); -} + new Assertion( + superset, + msg, + assert.notIncludeDeepOrderedMembers, + true + ).to.not.include.deep.ordered.members(subset); +}; /** * ### .oneOf(inList, list, [message]) @@ -2412,7 +2540,7 @@ assert.notIncludeDeepOrderedMembers = function (superset, subset, msg) { */ assert.oneOf = function (inList, list, msg) { new Assertion(inList, msg, assert.oneOf, true).to.be.oneOf(list); -} +}; /** * ### isIterable(obj, [message]) @@ -2427,19 +2555,15 @@ assert.oneOf = function (inList, list, msg) { * @namespace Assert * @public */ -assert.isIterable = function(obj, msg) { +assert.isIterable = function (obj, msg) { if (obj == undefined || !obj[Symbol.iterator]) { - msg = msg ? - `${msg} expected ${inspect(obj)} to be an iterable` : - `expected ${inspect(obj)} to be an iterable`; - - throw new AssertionError( - msg, - undefined, - assert.isIterable - ); + msg = msg + ? `${msg} expected ${inspect(obj)} to be an iterable` + : `expected ${inspect(obj)} to be an iterable`; + + throw new AssertionError(msg, undefined, assert.isIterable); } -} +}; /** * ### .changes(function, object, property, [message]) @@ -2465,7 +2589,7 @@ assert.changes = function (fn, obj, prop, msg) { } new Assertion(fn, msg, assert.changes, true).to.change(obj, prop); -} +}; /** * ### .changesBy(function, object, property, delta, [message]) @@ -2495,9 +2619,8 @@ assert.changesBy = function (fn, obj, prop, delta, msg) { prop = null; } - new Assertion(fn, msg, assert.changesBy, true) - .to.change(obj, prop).by(delta); -} + new Assertion(fn, msg, assert.changesBy, true).to.change(obj, prop).by(delta); +}; /** * ### .doesNotChange(function, object, property, [message]) @@ -2523,9 +2646,11 @@ assert.doesNotChange = function (fn, obj, prop, msg) { prop = null; } - return new Assertion(fn, msg, assert.doesNotChange, true) - .to.not.change(obj, prop); -} + return new Assertion(fn, msg, assert.doesNotChange, true).to.not.change( + obj, + prop + ); +}; /** * ### .changesButNotBy(function, object, property, delta, [message]) @@ -2555,9 +2680,10 @@ assert.changesButNotBy = function (fn, obj, prop, delta, msg) { prop = null; } - new Assertion(fn, msg, assert.changesButNotBy, true) - .to.change(obj, prop).but.not.by(delta); -} + new Assertion(fn, msg, assert.changesButNotBy, true).to + .change(obj, prop) + .but.not.by(delta); +}; /** * ### .increases(function, object, property, [message]) @@ -2583,9 +2709,8 @@ assert.increases = function (fn, obj, prop, msg) { prop = null; } - return new Assertion(fn, msg, assert.increases, true) - .to.increase(obj, prop); -} + return new Assertion(fn, msg, assert.increases, true).to.increase(obj, prop); +}; /** * ### .increasesBy(function, object, property, delta, [message]) @@ -2615,9 +2740,10 @@ assert.increasesBy = function (fn, obj, prop, delta, msg) { prop = null; } - new Assertion(fn, msg, assert.increasesBy, true) - .to.increase(obj, prop).by(delta); -} + new Assertion(fn, msg, assert.increasesBy, true).to + .increase(obj, prop) + .by(delta); +}; /** * ### .doesNotIncrease(function, object, property, [message]) @@ -2643,9 +2769,11 @@ assert.doesNotIncrease = function (fn, obj, prop, msg) { prop = null; } - return new Assertion(fn, msg, assert.doesNotIncrease, true) - .to.not.increase(obj, prop); -} + return new Assertion(fn, msg, assert.doesNotIncrease, true).to.not.increase( + obj, + prop + ); +}; /** * ### .increasesButNotBy(function, object, property, delta, [message]) @@ -2675,9 +2803,10 @@ assert.increasesButNotBy = function (fn, obj, prop, delta, msg) { prop = null; } - new Assertion(fn, msg, assert.increasesButNotBy, true) - .to.increase(obj, prop).but.not.by(delta); -} + new Assertion(fn, msg, assert.increasesButNotBy, true).to + .increase(obj, prop) + .but.not.by(delta); +}; /** * ### .decreases(function, object, property, [message]) @@ -2703,9 +2832,8 @@ assert.decreases = function (fn, obj, prop, msg) { prop = null; } - return new Assertion(fn, msg, assert.decreases, true) - .to.decrease(obj, prop); -} + return new Assertion(fn, msg, assert.decreases, true).to.decrease(obj, prop); +}; /** * ### .decreasesBy(function, object, property, delta, [message]) @@ -2735,9 +2863,10 @@ assert.decreasesBy = function (fn, obj, prop, delta, msg) { prop = null; } - new Assertion(fn, msg, assert.decreasesBy, true) - .to.decrease(obj, prop).by(delta); -} + new Assertion(fn, msg, assert.decreasesBy, true).to + .decrease(obj, prop) + .by(delta); +}; /** * ### .doesNotDecrease(function, object, property, [message]) @@ -2763,9 +2892,11 @@ assert.doesNotDecrease = function (fn, obj, prop, msg) { prop = null; } - return new Assertion(fn, msg, assert.doesNotDecrease, true) - .to.not.decrease(obj, prop); -} + return new Assertion(fn, msg, assert.doesNotDecrease, true).to.not.decrease( + obj, + prop + ); +}; /** * ### .doesNotDecreaseBy(function, object, property, delta, [message]) @@ -2796,9 +2927,10 @@ assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) { prop = null; } - return new Assertion(fn, msg, assert.doesNotDecreaseBy, true) - .to.not.decrease(obj, prop).by(delta); -} + return new Assertion(fn, msg, assert.doesNotDecreaseBy, true).to.not + .decrease(obj, prop) + .by(delta); +}; /** * ### .decreasesButNotBy(function, object, property, delta, [message]) @@ -2828,9 +2960,10 @@ assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) { prop = null; } - new Assertion(fn, msg, assert.decreasesButNotBy, true) - .to.decrease(obj, prop).but.not.by(delta); -} + new Assertion(fn, msg, assert.decreasesButNotBy, true).to + .decrease(obj, prop) + .but.not.by(delta); +}; /** * ### .ifError(object) @@ -2849,7 +2982,7 @@ assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) { */ assert.ifError = function (val) { if (val) { - throw(val); + throw val; } }; @@ -2995,7 +3128,7 @@ assert.isNotFrozen = function (obj, msg) { * @namespace Assert * @public */ -assert.isEmpty = function(val, msg) { +assert.isEmpty = function (val, msg) { new Assertion(val, msg, assert.isEmpty, true).to.be.empty; }; @@ -3020,7 +3153,7 @@ assert.isEmpty = function(val, msg) { * @namespace Assert * @public */ -assert.isNotEmpty = function(val, msg) { +assert.isNotEmpty = function (val, msg) { new Assertion(val, msg, assert.isNotEmpty, true).to.not.be.empty; }; @@ -3031,21 +3164,16 @@ assert.isNotEmpty = function(val, msg) { * @param {unknown} as * @returns {unknown} */ -(function alias(name, as){ +(function alias(name, as) { assert[as] = assert[name]; return alias; -}) -('isOk', 'ok') -('isNotOk', 'notOk') -('throws', 'throw') -('throws', 'Throw') -('isExtensible', 'extensible') -('isNotExtensible', 'notExtensible') -('isSealed', 'sealed') -('isNotSealed', 'notSealed') -('isFrozen', 'frozen') -('isNotFrozen', 'notFrozen') -('isEmpty', 'empty') -('isNotEmpty', 'notEmpty') -('isCallable', 'isFunction') -('isNotCallable', 'isNotFunction') +})('isOk', 'ok')('isNotOk', 'notOk')('throws', 'throw')('throws', 'Throw')( + 'isExtensible', + 'extensible' +)('isNotExtensible', 'notExtensible')('isSealed', 'sealed')( + 'isNotSealed', + 'notSealed' +)('isFrozen', 'frozen')('isNotFrozen', 'notFrozen')('isEmpty', 'empty')( + 'isNotEmpty', + 'notEmpty' +)('isCallable', 'isFunction')('isNotCallable', 'isNotFunction'); diff --git a/lib/chai/interface/expect.js b/lib/chai/interface/expect.js index fbaabf84..b7c76930 100644 --- a/lib/chai/interface/expect.js +++ b/lib/chai/interface/expect.js @@ -42,14 +42,18 @@ export {expect}; */ expect.fail = function (actual, expected, message, operator) { if (arguments.length < 2) { - message = actual; - actual = undefined; + message = actual; + actual = undefined; } message = message || 'expect.fail()'; - throw new AssertionError(message, { - actual: actual - , expected: expected - , operator: operator - }, chai.expect.fail); + throw new AssertionError( + message, + { + actual: actual, + expected: expected, + operator: operator + }, + chai.expect.fail + ); }; diff --git a/lib/chai/interface/should.js b/lib/chai/interface/should.js index 0efef3c6..2500fda5 100644 --- a/lib/chai/interface/should.js +++ b/lib/chai/interface/should.js @@ -10,17 +10,19 @@ import {AssertionError} from 'assertion-error'; /** * @returns {void} */ -function loadShould () { +function loadShould() { // explicitly define this method as function as to have it's name to include as `ssfi` /** * @returns {Assertion} */ function shouldGetter() { - if (this instanceof String - || this instanceof Number - || this instanceof Boolean - || typeof Symbol === 'function' && this instanceof Symbol - || typeof BigInt === 'function' && this instanceof BigInt) { + if ( + this instanceof String || + this instanceof Number || + this instanceof Boolean || + (typeof Symbol === 'function' && this instanceof Symbol) || + (typeof BigInt === 'function' && this instanceof BigInt) + ) { return new Assertion(this.valueOf(), null, shouldGetter); } return new Assertion(this, null, shouldGetter); @@ -44,9 +46,9 @@ function loadShould () { } // modify Object.prototype to have `should` Object.defineProperty(Object.prototype, 'should', { - set: shouldSetter - , get: shouldGetter - , configurable: true + set: shouldSetter, + get: shouldGetter, + configurable: true }); var should = {}; @@ -74,16 +76,20 @@ function loadShould () { */ should.fail = function (actual, expected, message, operator) { if (arguments.length < 2) { - message = actual; - actual = undefined; + message = actual; + actual = undefined; } message = message || 'should.fail()'; - throw new AssertionError(message, { - actual: actual - , expected: expected - , operator: operator - }, should.fail); + throw new AssertionError( + message, + { + actual: actual, + expected: expected, + operator: operator + }, + should.fail + ); }; /** @@ -147,10 +153,10 @@ function loadShould () { */ should.exist = function (val, msg) { new Assertion(val, msg).to.exist; - } + }; // negation - should.not = {} + should.not = {}; /** * ### .not.equal(actual, expected, [message]) @@ -209,13 +215,13 @@ function loadShould () { */ should.not.exist = function (val, msg) { new Assertion(val, msg).to.not.exist; - } + }; should['throw'] = should['Throw']; should.not['throw'] = should.not['Throw']; return should; -}; +} export const should = loadShould; export const Should = loadShould; diff --git a/lib/chai/utils/addChainableMethod.js b/lib/chai/utils/addChainableMethod.js index 8de2b21a..1a000c6b 100644 --- a/lib/chai/utils/addChainableMethod.js +++ b/lib/chai/utils/addChainableMethod.js @@ -19,23 +19,22 @@ var canSetPrototype = typeof Object.setPrototypeOf === 'function'; // Without `Object.setPrototypeOf` support, this module will need to add properties to a function. // However, some of functions' own props are not configurable and should be skipped. -var testFn = function() {}; -var excludeNames = Object.getOwnPropertyNames(testFn).filter(function(name) { +var testFn = function () {}; +var excludeNames = Object.getOwnPropertyNames(testFn).filter(function (name) { var propDesc = Object.getOwnPropertyDescriptor(testFn, name); // Note: PhantomJS 1.x includes `callee` as one of `testFn`'s own properties, // but then returns `undefined` as the property descriptor for `callee`. As a // workaround, we perform an otherwise unnecessary type-check for `propDesc`, // and then filter it out if it's not an object as it should be. - if (typeof propDesc !== 'object') - return true; + if (typeof propDesc !== 'object') return true; return !propDesc.configurable; }); // Cache `Function` properties -var call = Function.prototype.call, - apply = Function.prototype.apply; +var call = Function.prototype.call, + apply = Function.prototype.apply; /** * ### .addChainableMethod(ctx, name, method, chainingBehavior) @@ -67,12 +66,12 @@ var call = Function.prototype.call, */ export function addChainableMethod(ctx, name, method, chainingBehavior) { if (typeof chainingBehavior !== 'function') { - chainingBehavior = function () { }; + chainingBehavior = function () {}; } var chainableBehavior = { - method: method - , chainingBehavior: chainingBehavior + method: method, + chainingBehavior: chainingBehavior }; // save the methods so we can overwrite them later, if we need to. @@ -81,67 +80,67 @@ export function addChainableMethod(ctx, name, method, chainingBehavior) { } ctx.__methods[name] = chainableBehavior; - Object.defineProperty(ctx, name, - { get: function chainableMethodGetter() { - chainableBehavior.chainingBehavior.call(this); - - var chainableMethodWrapper = function () { - // Setting the `ssfi` flag to `chainableMethodWrapper` causes this - // function to be the starting point for removing implementation - // frames from the stack trace of a failed assertion. - // - // However, we only want to use this function as the starting point if - // the `lockSsfi` flag isn't set. - // - // If the `lockSsfi` flag is set, then this assertion is being - // invoked from inside of another assertion. In this case, the `ssfi` - // flag has already been set by the outer assertion. - // - // Note that overwriting a chainable method merely replaces the saved - // methods in `ctx.__methods` instead of completely replacing the - // overwritten assertion. Therefore, an overwriting assertion won't - // set the `ssfi` or `lockSsfi` flags. - if (!flag(this, 'lockSsfi')) { - flag(this, 'ssfi', chainableMethodWrapper); - } - - var result = chainableBehavior.method.apply(this, arguments); - if (result !== undefined) { - return result; - } - - var newAssertion = new Assertion(); - transferFlags(this, newAssertion); - return newAssertion; - }; - - addLengthGuard(chainableMethodWrapper, name, true); - - // Use `Object.setPrototypeOf` if available - if (canSetPrototype) { - // Inherit all properties from the object by replacing the `Function` prototype - var prototype = Object.create(this); - // Restore the `call` and `apply` methods from `Function` - prototype.call = call; - prototype.apply = apply; - Object.setPrototypeOf(chainableMethodWrapper, prototype); + Object.defineProperty(ctx, name, { + get: function chainableMethodGetter() { + chainableBehavior.chainingBehavior.call(this); + + var chainableMethodWrapper = function () { + // Setting the `ssfi` flag to `chainableMethodWrapper` causes this + // function to be the starting point for removing implementation + // frames from the stack trace of a failed assertion. + // + // However, we only want to use this function as the starting point if + // the `lockSsfi` flag isn't set. + // + // If the `lockSsfi` flag is set, then this assertion is being + // invoked from inside of another assertion. In this case, the `ssfi` + // flag has already been set by the outer assertion. + // + // Note that overwriting a chainable method merely replaces the saved + // methods in `ctx.__methods` instead of completely replacing the + // overwritten assertion. Therefore, an overwriting assertion won't + // set the `ssfi` or `lockSsfi` flags. + if (!flag(this, 'lockSsfi')) { + flag(this, 'ssfi', chainableMethodWrapper); } - // Otherwise, redefine all properties (slow!) - else { - var asserterNames = Object.getOwnPropertyNames(ctx); - asserterNames.forEach(function (asserterName) { - if (excludeNames.indexOf(asserterName) !== -1) { - return; - } - - var pd = Object.getOwnPropertyDescriptor(ctx, asserterName); - Object.defineProperty(chainableMethodWrapper, asserterName, pd); - }); + + var result = chainableBehavior.method.apply(this, arguments); + if (result !== undefined) { + return result; } - transferFlags(this, chainableMethodWrapper); - return proxify(chainableMethodWrapper); + var newAssertion = new Assertion(); + transferFlags(this, newAssertion); + return newAssertion; + }; + + addLengthGuard(chainableMethodWrapper, name, true); + + // Use `Object.setPrototypeOf` if available + if (canSetPrototype) { + // Inherit all properties from the object by replacing the `Function` prototype + var prototype = Object.create(this); + // Restore the `call` and `apply` methods from `Function` + prototype.call = call; + prototype.apply = apply; + Object.setPrototypeOf(chainableMethodWrapper, prototype); } - , configurable: true + // Otherwise, redefine all properties (slow!) + else { + var asserterNames = Object.getOwnPropertyNames(ctx); + asserterNames.forEach(function (asserterName) { + if (excludeNames.indexOf(asserterName) !== -1) { + return; + } + + var pd = Object.getOwnPropertyDescriptor(ctx, asserterName); + Object.defineProperty(chainableMethodWrapper, asserterName, pd); + }); + } + + transferFlags(this, chainableMethodWrapper); + return proxify(chainableMethodWrapper); + }, + configurable: true }); } diff --git a/lib/chai/utils/addLengthGuard.js b/lib/chai/utils/addLengthGuard.js index 621d7400..d08aad61 100644 --- a/lib/chai/utils/addLengthGuard.js +++ b/lib/chai/utils/addLengthGuard.js @@ -46,13 +46,26 @@ export function addLengthGuard(fn, assertionName, isChainable) { Object.defineProperty(fn, 'length', { get: function () { if (isChainable) { - throw Error('Invalid Chai property: ' + assertionName + '.length. Due' + - ' to a compatibility issue, "length" cannot directly follow "' + - assertionName + '". Use "' + assertionName + '.lengthOf" instead.'); + throw Error( + 'Invalid Chai property: ' + + assertionName + + '.length. Due' + + ' to a compatibility issue, "length" cannot directly follow "' + + assertionName + + '". Use "' + + assertionName + + '.lengthOf" instead.' + ); } - throw Error('Invalid Chai property: ' + assertionName + '.length. See' + - ' docs for proper usage of "' + assertionName + '".'); + throw Error( + 'Invalid Chai property: ' + + assertionName + + '.length. See' + + ' docs for proper usage of "' + + assertionName + + '".' + ); } }); diff --git a/lib/chai/utils/addMethod.js b/lib/chai/utils/addMethod.js index 90b9546c..de5b04fc 100644 --- a/lib/chai/utils/addMethod.js +++ b/lib/chai/utils/addMethod.js @@ -54,8 +54,7 @@ export function addMethod(ctx, name, method) { } var result = method.apply(this, arguments); - if (result !== undefined) - return result; + if (result !== undefined) return result; var newAssertion = new Assertion(); transferFlags(this, newAssertion); diff --git a/lib/chai/utils/addProperty.js b/lib/chai/utils/addProperty.js index fa59d23e..4375d61a 100644 --- a/lib/chai/utils/addProperty.js +++ b/lib/chai/utils/addProperty.js @@ -37,35 +37,34 @@ import {transferFlags} from './transferFlags.js'; export function addProperty(ctx, name, getter) { getter = getter === undefined ? function () {} : getter; - Object.defineProperty(ctx, name, - { get: function propertyGetter() { - // Setting the `ssfi` flag to `propertyGetter` causes this function to - // be the starting point for removing implementation frames from the - // stack trace of a failed assertion. - // - // However, we only want to use this function as the starting point if - // the `lockSsfi` flag isn't set and proxy protection is disabled. - // - // If the `lockSsfi` flag is set, then either this assertion has been - // overwritten by another assertion, or this assertion is being invoked - // from inside of another assertion. In the first case, the `ssfi` flag - // has already been set by the overwriting assertion. In the second - // case, the `ssfi` flag has already been set by the outer assertion. - // - // If proxy protection is enabled, then the `ssfi` flag has already been - // set by the proxy getter. - if (!isProxyEnabled() && !flag(this, 'lockSsfi')) { - flag(this, 'ssfi', propertyGetter); - } + Object.defineProperty(ctx, name, { + get: function propertyGetter() { + // Setting the `ssfi` flag to `propertyGetter` causes this function to + // be the starting point for removing implementation frames from the + // stack trace of a failed assertion. + // + // However, we only want to use this function as the starting point if + // the `lockSsfi` flag isn't set and proxy protection is disabled. + // + // If the `lockSsfi` flag is set, then either this assertion has been + // overwritten by another assertion, or this assertion is being invoked + // from inside of another assertion. In the first case, the `ssfi` flag + // has already been set by the overwriting assertion. In the second + // case, the `ssfi` flag has already been set by the outer assertion. + // + // If proxy protection is enabled, then the `ssfi` flag has already been + // set by the proxy getter. + if (!isProxyEnabled() && !flag(this, 'lockSsfi')) { + flag(this, 'ssfi', propertyGetter); + } - var result = getter.call(this); - if (result !== undefined) - return result; + var result = getter.call(this); + if (result !== undefined) return result; - var newAssertion = new Assertion(); - transferFlags(this, newAssertion); - return newAssertion; - } - , configurable: true + var newAssertion = new Assertion(); + transferFlags(this, newAssertion); + return newAssertion; + }, + configurable: true }); } diff --git a/lib/chai/utils/expectTypes.js b/lib/chai/utils/expectTypes.js index 4f99532f..ca2e1601 100644 --- a/lib/chai/utils/expectTypes.js +++ b/lib/chai/utils/expectTypes.js @@ -28,19 +28,27 @@ export function expectTypes(obj, types) { flagMsg = flagMsg ? flagMsg + ': ' : ''; obj = flag(obj, 'object'); - types = types.map(function (t) { return t.toLowerCase(); }); + types = types.map(function (t) { + return t.toLowerCase(); + }); types.sort(); // Transforms ['lorem', 'ipsum'] into 'a lorem, or an ipsum' - var str = types.map(function (t, index) { - var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a'; - var or = types.length > 1 && index === types.length - 1 ? 'or ' : ''; - return or + art + ' ' + t; - }).join(', '); + var str = types + .map(function (t, index) { + var art = ~['a', 'e', 'i', 'o', 'u'].indexOf(t.charAt(0)) ? 'an' : 'a'; + var or = types.length > 1 && index === types.length - 1 ? 'or ' : ''; + return or + art + ' ' + t; + }) + .join(', '); var objType = type(obj).toLowerCase(); - if (!types.some(function (expected) { return objType === expected; })) { + if ( + !types.some(function (expected) { + return objType === expected; + }) + ) { throw new AssertionError( flagMsg + 'object tested must be ' + str + ', but ' + objType + ' given', undefined, diff --git a/lib/chai/utils/getMessage.js b/lib/chai/utils/getMessage.js index b184c990..faa841f2 100644 --- a/lib/chai/utils/getMessage.js +++ b/lib/chai/utils/getMessage.js @@ -28,19 +28,25 @@ import {objDisplay} from './objDisplay.js'; * @public */ export function getMessage(obj, args) { - var negate = flag(obj, 'negate') - , val = flag(obj, 'object') - , expected = args[3] - , actual = getActual(obj, args) - , msg = negate ? args[2] : args[1] - , flagMsg = flag(obj, 'message'); + var negate = flag(obj, 'negate'), + val = flag(obj, 'object'), + expected = args[3], + actual = getActual(obj, args), + msg = negate ? args[2] : args[1], + flagMsg = flag(obj, 'message'); - if(typeof msg === "function") msg = msg(); + if (typeof msg === 'function') msg = msg(); msg = msg || ''; msg = msg - .replace(/#\{this\}/g, function () { return objDisplay(val); }) - .replace(/#\{act\}/g, function () { return objDisplay(actual); }) - .replace(/#\{exp\}/g, function () { return objDisplay(expected); }); + .replace(/#\{this\}/g, function () { + return objDisplay(val); + }) + .replace(/#\{act\}/g, function () { + return objDisplay(actual); + }) + .replace(/#\{exp\}/g, function () { + return objDisplay(expected); + }); return flagMsg ? flagMsg + ': ' + msg : msg; } diff --git a/lib/chai/utils/index.js b/lib/chai/utils/index.js index fd4e6358..b9029bba 100644 --- a/lib/chai/utils/index.js +++ b/lib/chai/utils/index.js @@ -48,7 +48,7 @@ export {getPathInfo, hasProperty} from 'pathval'; * @returns {string} */ export function getName(fn) { - return fn.name + return fn.name; } // add Property @@ -108,5 +108,5 @@ export function isRegExp(obj) { } export function isNumeric(obj) { - return ['Number', 'BigInt'].includes(type(obj)) + return ['Number', 'BigInt'].includes(type(obj)); } diff --git a/lib/chai/utils/inspect.js b/lib/chai/utils/inspect.js index dcd9ad79..f27bf341 100644 --- a/lib/chai/utils/inspect.js +++ b/lib/chai/utils/inspect.js @@ -23,9 +23,9 @@ import {config} from '../config.js'; export function inspect(obj, showHidden, depth, colors) { var options = { colors: colors, - depth: (typeof depth === 'undefined' ? 2 : depth), + depth: typeof depth === 'undefined' ? 2 : depth, showHidden: showHidden, - truncate: config.truncateThreshold ? config.truncateThreshold : Infinity, + truncate: config.truncateThreshold ? config.truncateThreshold : Infinity }; return _inspect(obj, options); } diff --git a/lib/chai/utils/isProxyEnabled.js b/lib/chai/utils/isProxyEnabled.js index 5b6b62aa..dd68d4d1 100644 --- a/lib/chai/utils/isProxyEnabled.js +++ b/lib/chai/utils/isProxyEnabled.js @@ -18,7 +18,9 @@ import {config} from '../config.js'; * @returns {boolean} */ export function isProxyEnabled() { - return config.useProxy && + return ( + config.useProxy && typeof Proxy !== 'undefined' && - typeof Reflect !== 'undefined'; + typeof Reflect !== 'undefined' + ); } diff --git a/lib/chai/utils/objDisplay.js b/lib/chai/utils/objDisplay.js index 76f014a8..cf58d5da 100644 --- a/lib/chai/utils/objDisplay.js +++ b/lib/chai/utils/objDisplay.js @@ -21,8 +21,8 @@ import {config} from '../config.js'; * @public */ export function objDisplay(obj) { - var str = inspect(obj) - , type = Object.prototype.toString.call(obj); + var str = inspect(obj), + type = Object.prototype.toString.call(obj); if (config.truncateThreshold && str.length >= config.truncateThreshold) { if (type === '[object Function]') { @@ -32,10 +32,11 @@ export function objDisplay(obj) { } else if (type === '[object Array]') { return '[ Array(' + obj.length + ') ]'; } else if (type === '[object Object]') { - var keys = Object.keys(obj) - , kstr = keys.length > 2 - ? keys.splice(0, 2).join(', ') + ', ...' - : keys.join(', '); + var keys = Object.keys(obj), + kstr = + keys.length > 2 + ? keys.splice(0, 2).join(', ') + ', ...' + : keys.join(', '); return '{ Object (' + kstr + ') }'; } else { return str; diff --git a/lib/chai/utils/overwriteChainableMethod.js b/lib/chai/utils/overwriteChainableMethod.js index 68fc89f6..27fce9f4 100644 --- a/lib/chai/utils/overwriteChainableMethod.js +++ b/lib/chai/utils/overwriteChainableMethod.js @@ -43,16 +43,17 @@ export function overwriteChainableMethod(ctx, name, method, chainingBehavior) { var chainableBehavior = ctx.__methods[name]; var _chainingBehavior = chainableBehavior.chainingBehavior; - chainableBehavior.chainingBehavior = function overwritingChainableMethodGetter() { - var result = chainingBehavior(_chainingBehavior).call(this); - if (result !== undefined) { - return result; - } + chainableBehavior.chainingBehavior = + function overwritingChainableMethodGetter() { + var result = chainingBehavior(_chainingBehavior).call(this); + if (result !== undefined) { + return result; + } - var newAssertion = new Assertion(); - transferFlags(this, newAssertion); - return newAssertion; - }; + var newAssertion = new Assertion(); + transferFlags(this, newAssertion); + return newAssertion; + }; var _method = chainableBehavior.method; chainableBehavior.method = function overwritingChainableMethodWrapper() { diff --git a/lib/chai/utils/overwriteMethod.js b/lib/chai/utils/overwriteMethod.js index d101f3b0..0fbeb3be 100644 --- a/lib/chai/utils/overwriteMethod.js +++ b/lib/chai/utils/overwriteMethod.js @@ -44,13 +44,12 @@ import {transferFlags} from './transferFlags.js'; * @public */ export function overwriteMethod(ctx, name, method) { - var _method = ctx[name] - , _super = function () { + var _method = ctx[name], + _super = function () { throw new Error(name + ' is not a function'); }; - if (_method && 'function' === typeof _method) - _super = _method; + if (_method && 'function' === typeof _method) _super = _method; var overwritingMethodWrapper = function () { // Setting the `ssfi` flag to `overwritingMethodWrapper` causes this @@ -84,7 +83,7 @@ export function overwriteMethod(ctx, name, method) { var newAssertion = new Assertion(); transferFlags(this, newAssertion); return newAssertion; - } + }; addLengthGuard(overwritingMethodWrapper, name, false); ctx[name] = proxify(overwritingMethodWrapper, name); diff --git a/lib/chai/utils/overwriteProperty.js b/lib/chai/utils/overwriteProperty.js index 97f3486a..d1253093 100644 --- a/lib/chai/utils/overwriteProperty.js +++ b/lib/chai/utils/overwriteProperty.js @@ -42,49 +42,48 @@ import {transferFlags} from './transferFlags.js'; * @public */ export function overwriteProperty(ctx, name, getter) { - var _get = Object.getOwnPropertyDescriptor(ctx, name) - , _super = function () {}; + var _get = Object.getOwnPropertyDescriptor(ctx, name), + _super = function () {}; - if (_get && 'function' === typeof _get.get) - _super = _get.get + if (_get && 'function' === typeof _get.get) _super = _get.get; - Object.defineProperty(ctx, name, - { get: function overwritingPropertyGetter() { - // Setting the `ssfi` flag to `overwritingPropertyGetter` causes this - // function to be the starting point for removing implementation frames - // from the stack trace of a failed assertion. - // - // However, we only want to use this function as the starting point if - // the `lockSsfi` flag isn't set and proxy protection is disabled. - // - // If the `lockSsfi` flag is set, then either this assertion has been - // overwritten by another assertion, or this assertion is being invoked - // from inside of another assertion. In the first case, the `ssfi` flag - // has already been set by the overwriting assertion. In the second - // case, the `ssfi` flag has already been set by the outer assertion. - // - // If proxy protection is enabled, then the `ssfi` flag has already been - // set by the proxy getter. - if (!isProxyEnabled() && !flag(this, 'lockSsfi')) { - flag(this, 'ssfi', overwritingPropertyGetter); - } - - // Setting the `lockSsfi` flag to `true` prevents the overwritten - // assertion from changing the `ssfi` flag. By this point, the `ssfi` - // flag is already set to the correct starting point for this assertion. - var origLockSsfi = flag(this, 'lockSsfi'); - flag(this, 'lockSsfi', true); - var result = getter(_super).call(this); - flag(this, 'lockSsfi', origLockSsfi); + Object.defineProperty(ctx, name, { + get: function overwritingPropertyGetter() { + // Setting the `ssfi` flag to `overwritingPropertyGetter` causes this + // function to be the starting point for removing implementation frames + // from the stack trace of a failed assertion. + // + // However, we only want to use this function as the starting point if + // the `lockSsfi` flag isn't set and proxy protection is disabled. + // + // If the `lockSsfi` flag is set, then either this assertion has been + // overwritten by another assertion, or this assertion is being invoked + // from inside of another assertion. In the first case, the `ssfi` flag + // has already been set by the overwriting assertion. In the second + // case, the `ssfi` flag has already been set by the outer assertion. + // + // If proxy protection is enabled, then the `ssfi` flag has already been + // set by the proxy getter. + if (!isProxyEnabled() && !flag(this, 'lockSsfi')) { + flag(this, 'ssfi', overwritingPropertyGetter); + } - if (result !== undefined) { - return result; - } + // Setting the `lockSsfi` flag to `true` prevents the overwritten + // assertion from changing the `ssfi` flag. By this point, the `ssfi` + // flag is already set to the correct starting point for this assertion. + var origLockSsfi = flag(this, 'lockSsfi'); + flag(this, 'lockSsfi', true); + var result = getter(_super).call(this); + flag(this, 'lockSsfi', origLockSsfi); - var newAssertion = new Assertion(); - transferFlags(this, newAssertion); - return newAssertion; + if (result !== undefined) { + return result; } - , configurable: true + + var newAssertion = new Assertion(); + transferFlags(this, newAssertion); + return newAssertion; + }, + configurable: true }); } diff --git a/lib/chai/utils/proxify.js b/lib/chai/utils/proxify.js index 3789892f..19112f90 100644 --- a/lib/chai/utils/proxify.js +++ b/lib/chai/utils/proxify.js @@ -30,7 +30,7 @@ const builtins = ['__flags', '__methods', '_obj', 'assert']; * @namespace Utils * @name proxify */ -export function proxify(obj ,nonChainableMethodName) { +export function proxify(obj, nonChainableMethodName) { if (!isProxyEnabled()) return obj; return new Proxy(obj, { @@ -39,14 +39,22 @@ export function proxify(obj ,nonChainableMethodName) { // such as `Symbol.toStringTag`. // The values for which an error should be thrown can be configured using // the `config.proxyExcludedKeys` setting. - if (typeof property === 'string' && - config.proxyExcludedKeys.indexOf(property) === -1 && - !Reflect.has(target, property)) { + if ( + typeof property === 'string' && + config.proxyExcludedKeys.indexOf(property) === -1 && + !Reflect.has(target, property) + ) { // Special message for invalid property access of non-chainable methods. if (nonChainableMethodName) { - throw Error('Invalid Chai property: ' + nonChainableMethodName + '.' + - property + '. See docs for proper usage of "' + - nonChainableMethodName + '".'); + throw Error( + 'Invalid Chai property: ' + + nonChainableMethodName + + '.' + + property + + '. See docs for proper usage of "' + + nonChainableMethodName + + '".' + ); } // If the property is reasonably close to an existing Chai property, @@ -54,16 +62,12 @@ export function proxify(obj ,nonChainableMethodName) { // distance less than 4. var suggestion = null; var suggestionDistance = 4; - getProperties(target).forEach(function(prop) { + getProperties(target).forEach(function (prop) { if ( !Object.prototype.hasOwnProperty(prop) && builtins.indexOf(prop) === -1 ) { - var dist = stringDistanceCapped( - property, - prop, - suggestionDistance - ); + var dist = stringDistanceCapped(property, prop, suggestionDistance); if (dist < suggestionDistance) { suggestion = prop; suggestionDistance = dist; @@ -72,8 +76,13 @@ export function proxify(obj ,nonChainableMethodName) { }); if (suggestion !== null) { - throw Error('Invalid Chai property: ' + property + - '. Did you mean "' + suggestion + '"?'); + throw Error( + 'Invalid Chai property: ' + + property + + '. Did you mean "' + + suggestion + + '"?' + ); } else { throw Error('Invalid Chai property: ' + property); } @@ -137,8 +146,7 @@ function stringDistanceCapped(strA, strB, cap) { memo[i][j] = Math.min( memo[i - 1][j] + 1, memo[i][j - 1] + 1, - memo[i - 1][j - 1] + - (ch === strB.charCodeAt(j - 1) ? 0 : 1) + memo[i - 1][j - 1] + (ch === strB.charCodeAt(j - 1) ? 0 : 1) ); } } diff --git a/lib/chai/utils/test.js b/lib/chai/utils/test.js index 2fc98cec..6d64aeb3 100644 --- a/lib/chai/utils/test.js +++ b/lib/chai/utils/test.js @@ -18,7 +18,7 @@ import {flag} from './flag.js'; * @name test */ export function test(obj, args) { - var negate = flag(obj, 'negate') - , expr = args[0]; + var negate = flag(obj, 'negate'), + expr = args[0]; return negate ? !expr : expr; } diff --git a/lib/chai/utils/transferFlags.js b/lib/chai/utils/transferFlags.js index 2669941c..4e5b785f 100644 --- a/lib/chai/utils/transferFlags.js +++ b/lib/chai/utils/transferFlags.js @@ -35,8 +35,13 @@ export function transferFlags(assertion, object, includeAll) { includeAll = arguments.length === 3 ? includeAll : true; for (var flag in flags) { - if (includeAll || - (flag !== 'object' && flag !== 'ssfi' && flag !== 'lockSsfi' && flag != 'message')) { + if ( + includeAll || + (flag !== 'object' && + flag !== 'ssfi' && + flag !== 'lockSsfi' && + flag != 'message') + ) { object.__flags[flag] = flags[flag]; } } diff --git a/lib/chai/utils/type-detect.js b/lib/chai/utils/type-detect.js index 995332b2..573edf81 100644 --- a/lib/chai/utils/type-detect.js +++ b/lib/chai/utils/type-detect.js @@ -6,7 +6,7 @@ export function type(obj) { if (typeof obj === 'undefined') { return 'undefined'; } - + if (obj === null) { return 'null'; } diff --git a/package-lock.json b/package-lock.json index 66e90ee5..89de19e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,8 @@ "esbuild": "^0.19.10", "eslint": "^8.56.0", "eslint-plugin-jsdoc": "^48.0.4", - "mocha": "^10.2.0" + "mocha": "^10.2.0", + "prettier": "^3.4.2" }, "engines": { "node": ">=12" @@ -5311,6 +5312,22 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", diff --git a/package.json b/package.json index cc8fb27b..f1d2c0cf 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,14 @@ "prebuild": "npm run clean", "build": "npm run build:esm", "build:esm": "esbuild --bundle --format=esm --keep-names --outfile=chai.js index.js", + "format": "prettier --write lib", "pretest": "npm run lint && npm run build", "test": "npm run test-node && npm run test-chrome", "test-node": "mocha --require ./test/bootstrap/index.js --reporter dot test/*.js", "test-chrome": "web-test-runner --playwright", - "lint": "eslint lib/", + "lint": "npm run lint:js && npm run lint:format", + "lint:js": "eslint lib/", + "lint:format": "prettier --check lib", "clean": "rm -f chai.js coverage" }, "engines": { @@ -56,6 +59,7 @@ "esbuild": "^0.19.10", "eslint": "^8.56.0", "eslint-plugin-jsdoc": "^48.0.4", - "mocha": "^10.2.0" + "mocha": "^10.2.0", + "prettier": "^3.4.2" } }