From 12a70f4aba61170632a136216492b9083351d121 Mon Sep 17 00:00:00 2001 From: Adi Prasetyo Date: Tue, 21 Nov 2017 20:15:50 +0700 Subject: [PATCH] Fix #1090 --- lib/chai/interface/assert.js | 106 +++++++++++++++++------------------ test/assert.js | 10 ++-- 2 files changed, 57 insertions(+), 59 deletions(-) diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 59e5f8b66..0f5613258 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -1012,24 +1012,24 @@ module.exports = function (chai, util) { /** * ### .nestedInclude(haystack, needle, [message]) - * - * Asserts that 'haystack' includes 'needle'. - * Can be used to assert the inclusion of a subset of properties in an + * + * Asserts that 'haystack' includes 'needle'. + * Can be used to assert the inclusion of a subset of properties in an * object. - * Enables the use of dot- and bracket-notation for referencing nested + * Enables the use of dot- and bracket-notation for referencing nested * properties. * '[]' and '.' in property names can be escaped using double backslashes. - * + * * assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'}); * assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'}); - * + * * @name nestedInclude * @param {Object} haystack * @param {Object} needle * @param {String} message * @namespace Assert - * @api public - */ + * @api public + */ assert.nestedInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc); @@ -1037,24 +1037,24 @@ module.exports = function (chai, util) { /** * ### .notNestedInclude(haystack, needle, [message]) - * - * Asserts that 'haystack' does not include 'needle'. - * Can be used to assert the absence of a subset of properties in an + * + * Asserts that 'haystack' does not include 'needle'. + * Can be used to assert the absence of a subset of properties in an * object. - * Enables the use of dot- and bracket-notation for referencing nested - * properties. + * Enables the use of dot- and bracket-notation for referencing nested + * properties. * '[]' and '.' in property names can be escaped using double backslashes. - * + * * assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'}); * assert.notNestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'y'}); - * + * * @name notNestedInclude * @param {Object} haystack * @param {Object} needle * @param {String} message * @namespace Assert - * @api public - */ + * @api public + */ assert.notNestedInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.notNestedInclude, true) @@ -1063,23 +1063,23 @@ module.exports = function (chai, util) { /** * ### .deepNestedInclude(haystack, needle, [message]) - * + * * Asserts that 'haystack' includes 'needle'. - * Can be used to assert the inclusion of a subset of properties in an + * Can be used to assert the inclusion of a subset of properties in an * object while checking for deep equality. - * Enables the use of dot- and bracket-notation for referencing nested + * Enables the use of dot- and bracket-notation for referencing nested * properties. * '[]' and '.' in property names can be escaped using double backslashes. - * + * * assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}}); * assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}}); - * + * * @name deepNestedInclude * @param {Object} haystack * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @api public */ assert.deepNestedInclude = function(exp, inc, msg) { @@ -1089,23 +1089,23 @@ module.exports = function (chai, util) { /** * ### .notDeepNestedInclude(haystack, needle, [message]) - * + * * Asserts that 'haystack' does not include 'needle'. - * Can be used to assert the absence of a subset of properties in an + * Can be used to assert the absence of a subset of properties in an * object while checking for deep equality. - * Enables the use of dot- and bracket-notation for referencing nested + * Enables the use of dot- and bracket-notation for referencing nested * properties. * '[]' and '.' in property names can be escaped using double backslashes. - * + * * assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}}) * assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}}); - * + * * @name notDeepNestedInclude * @param {Object} haystack * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @api public */ assert.notDeepNestedInclude = function(exp, inc, msg) { @@ -1115,13 +1115,13 @@ module.exports = function (chai, util) { /** * ### .ownInclude(haystack, needle, [message]) - * + * * Asserts that 'haystack' includes 'needle'. - * Can be used to assert the inclusion of a subset of properties in an + * Can be used to assert the inclusion of a subset of properties in an * object while ignoring inherited properties. - * + * * assert.ownInclude({ a: 1 }, { a: 1 }); - * + * * @name ownInclude * @param {Object} haystack * @param {Object} needle @@ -1136,15 +1136,15 @@ module.exports = function (chai, util) { /** * ### .notOwnInclude(haystack, needle, [message]) - * + * * Asserts that 'haystack' includes 'needle'. - * Can be used to assert the absence of a subset of properties in an + * Can be used to assert the absence of a subset of properties in an * object while ignoring inherited properties. - * + * * Object.prototype.b = 2; - * + * * assert.notOwnInclude({ a: 1 }, { b: 2 }); - * + * * @name notOwnInclude * @param {Object} haystack * @param {Object} needle @@ -1159,13 +1159,13 @@ module.exports = function (chai, util) { /** * ### .deepOwnInclude(haystack, needle, [message]) - * + * * Asserts that 'haystack' includes 'needle'. - * Can be used to assert the inclusion of a subset of properties in an + * Can be used to assert the inclusion of a subset of properties in an * object while ignoring inherited properties and checking for deep equality. - * + * * assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}}); - * + * * @name deepOwnInclude * @param {Object} haystack * @param {Object} needle @@ -1181,13 +1181,13 @@ module.exports = function (chai, util) { /** * ### .notDeepOwnInclude(haystack, needle, [message]) - * + * * Asserts that 'haystack' includes 'needle'. - * Can be used to assert the absence of a subset of properties in an + * Can be used to assert the absence of a subset of properties in an * object while ignoring inherited properties and checking for deep equality. - * + * * assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}}); - * + * * @name notDeepOwnInclude * @param {Object} haystack * @param {Object} needle @@ -2645,7 +2645,7 @@ module.exports = function (chai, util) { assert.increasesBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; - delta = prop; + prop = null; msg = tmpMsg; } else if (arguments.length === 3) { delta = prop; @@ -2705,9 +2705,8 @@ module.exports = function (chai, util) { assert.increasesButNotBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { - var tmpMsg = delta; - delta = prop; - msg = tmpMsg; + msg = 'getter function'; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; @@ -2767,8 +2766,8 @@ module.exports = function (chai, util) { assert.decreasesBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; - delta = prop; msg = tmpMsg; + prop = null; } else if (arguments.length === 3) { delta = prop; prop = null; @@ -2860,9 +2859,8 @@ module.exports = function (chai, util) { assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { - var tmpMsg = delta; - delta = prop; - msg = tmpMsg; + msg = 'getter function'; + prop= null; } else if (arguments.length === 3) { delta = prop; prop = null; diff --git a/test/assert.js b/test/assert.js index 99adb662a..e8a1ae37e 100644 --- a/test/assert.js +++ b/test/assert.js @@ -2086,7 +2086,7 @@ describe('assert', function () { err(function() { assert.isAbove(now, now, 'blah'); }, 'blah: expected ' + now.toUTCString() + ' to be above ' + now.toUTCString()); - + err(function() { assert.isAbove(null, now); }, 'expected null to be a number or a date'); @@ -2315,18 +2315,18 @@ describe('assert', function () { assert.doesNotDecrease(smFn, obj, 'value'); assert.doesNotDecrease(smFn, getterFn, 'value'); assert.decreasesBy(decFn, obj, 'value', 3); - // assert.decreasesBy(decFn, getterFn, 'value', 3); + assert.decreasesBy(decFn, getterFn, 'value', 3); assert.decreasesButNotBy(decFn, obj, 'value', 10); - // assert.decreasesButNotBy(decFn, getterFn, 'value', 10); + assert.decreasesButNotBy(decFn, getterFn, 'value', 11); assert.increases(incFn, obj, 'value'); assert.increases(incFn, getterFn, 'value'); assert.doesNotIncrease(smFn, obj, 'value'); assert.doesNotIncrease(smFn, getterFn, 'value'); assert.increasesBy(incFn, obj, 'value', 2); - // assert.increasesBy(incFn, getterFn, 'value', 2); + assert.increasesBy(incFn, getterFn, 'value', 2); assert.increasesButNotBy(incFn, obj, 'value', 1); - // assert.increasesButNotBy(incFn, getterFn, 'value', 1); + assert.increasesButNotBy(incFn, getterFn, 'value', 3); assert.decreases(popFn, lenFn); assert.doesNotDecrease(pFn, lenFn);