Skip to content

Commit 8a24666

Browse files
committed
1 parent 9635906 commit 8a24666

File tree

4 files changed

+64
-30
lines changed

4 files changed

+64
-30
lines changed

chai.js

+61-27
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var used = [];
1414
* Chai version
1515
*/
1616

17-
exports.version = '4.3.0';
17+
exports.version = '4.3.1';
1818

1919
/*!
2020
* Assertion Error
@@ -405,6 +405,7 @@ module.exports = function (chai, _) {
405405
* - but
406406
* - does
407407
* - still
408+
* - also
408409
*
409410
* @name language chains
410411
* @namespace BDD
@@ -414,7 +415,7 @@ module.exports = function (chai, _) {
414415
[ 'to', 'be', 'been', 'is'
415416
, 'and', 'has', 'have', 'with'
416417
, 'that', 'which', 'at', 'of'
417-
, 'same', 'but', 'does', 'still' ].forEach(function (chain) {
418+
, 'same', 'but', 'does', 'still', "also" ].forEach(function (chain) {
418419
Assertion.addProperty(chain);
419420
});
420421

@@ -1194,19 +1195,25 @@ module.exports = function (chai, _) {
11941195
*
11951196
* expect(null, 'nooo why fail??').to.exist;
11961197
*
1198+
* The alias `.exists` can be used interchangeably with `.exist`.
1199+
*
11971200
* @name exist
1201+
* @alias exists
11981202
* @namespace BDD
11991203
* @api public
12001204
*/
12011205

1202-
Assertion.addProperty('exist', function () {
1206+
function assertExist () {
12031207
var val = flag(this, 'object');
12041208
this.assert(
12051209
val !== null && val !== undefined
12061210
, 'expected #{this} to exist'
12071211
, 'expected #{this} to not exist'
12081212
);
1209-
});
1213+
}
1214+
1215+
Assertion.addProperty('exist', assertExist);
1216+
Assertion.addProperty('exists', assertExist);
12101217

12111218
/**
12121219
* ### .empty
@@ -1606,10 +1613,12 @@ module.exports = function (chai, _) {
16061613
* expect(1).to.be.at.least(2, 'nooo why fail??');
16071614
* expect(1, 'nooo why fail??').to.be.at.least(2);
16081615
*
1609-
* The alias `.gte` can be used interchangeably with `.least`.
1616+
* The aliases `.gte` and `.greaterThanOrEqual` can be used interchangeably with
1617+
* `.least`.
16101618
*
16111619
* @name least
16121620
* @alias gte
1621+
* @alias greaterThanOrEqual
16131622
* @param {Number} n
16141623
* @param {String} msg _optional_
16151624
* @namespace BDD
@@ -1675,6 +1684,7 @@ module.exports = function (chai, _) {
16751684

16761685
Assertion.addMethod('least', assertLeast);
16771686
Assertion.addMethod('gte', assertLeast);
1687+
Assertion.addMethod('greaterThanOrEqual', assertLeast);
16781688

16791689
/**
16801690
* ### .below(n[, msg])
@@ -1812,10 +1822,12 @@ module.exports = function (chai, _) {
18121822
* expect(2).to.be.at.most(1, 'nooo why fail??');
18131823
* expect(2, 'nooo why fail??').to.be.at.most(1);
18141824
*
1815-
* The alias `.lte` can be used interchangeably with `.most`.
1825+
* The aliases `.lte` and `.lessThanOrEqual` can be used interchangeably with
1826+
* `.most`.
18161827
*
18171828
* @name most
18181829
* @alias lte
1830+
* @alias lessThanOrEqual
18191831
* @param {Number} n
18201832
* @param {String} msg _optional_
18211833
* @namespace BDD
@@ -1881,6 +1893,7 @@ module.exports = function (chai, _) {
18811893

18821894
Assertion.addMethod('most', assertMost);
18831895
Assertion.addMethod('lte', assertMost);
1896+
Assertion.addMethod('lessThanOrEqual', assertMost);
18841897

18851898
/**
18861899
* ### .within(start, finish[, msg])
@@ -3521,7 +3534,8 @@ module.exports = function (chai, _) {
35213534
var expected = flag(this, 'object')
35223535
, flagMsg = flag(this, 'message')
35233536
, ssfi = flag(this, 'ssfi')
3524-
, contains = flag(this, 'contains');
3537+
, contains = flag(this, 'contains')
3538+
, isDeep = flag(this, 'deep');
35253539
new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
35263540

35273541
if (contains) {
@@ -3533,13 +3547,23 @@ module.exports = function (chai, _) {
35333547
, expected
35343548
);
35353549
} else {
3536-
this.assert(
3537-
list.indexOf(expected) > -1
3538-
, 'expected #{this} to be one of #{exp}'
3539-
, 'expected #{this} to not be one of #{exp}'
3540-
, list
3541-
, expected
3542-
);
3550+
if (isDeep) {
3551+
this.assert(
3552+
list.some(possibility => _.eql(expected, possibility))
3553+
, 'expected #{this} to deeply equal one of #{exp}'
3554+
, 'expected #{this} to deeply equal one of #{exp}'
3555+
, list
3556+
, expected
3557+
);
3558+
} else {
3559+
this.assert(
3560+
list.indexOf(expected) > -1
3561+
, 'expected #{this} to be one of #{exp}'
3562+
, 'expected #{this} to not be one of #{exp}'
3563+
, list
3564+
, expected
3565+
);
3566+
}
35433567
}
35443568
}
35453569

@@ -6462,7 +6486,7 @@ module.exports = function (chai, util) {
64626486
* Asserts that `set1` and `set2` have the same members in the same order.
64636487
* Uses a deep equality check.
64646488
*
6465-
* assert.sameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { c: 3 } ], 'same deep ordered members');
6489+
* assert.sameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { c: 3 } ], 'same deep ordered members');
64666490
*
64676491
* @name sameDeepOrderedMembers
64686492
* @param {Array} set1
@@ -6483,8 +6507,8 @@ module.exports = function (chai, util) {
64836507
* Asserts that `set1` and `set2` don't have the same members in the same
64846508
* order. Uses a deep equality check.
64856509
*
6486-
* assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { z: 5 } ], 'not same deep ordered members');
6487-
* assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 }, { c: 3 } ], 'not same deep ordered members');
6510+
* assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { z: 5 } ], 'not same deep ordered members');
6511+
* assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 }, { c: 3 } ], 'not same deep ordered members');
64886512
*
64896513
* @name notSameDeepOrderedMembers
64906514
* @param {Array} set1
@@ -6904,7 +6928,7 @@ module.exports = function (chai, util) {
69046928
}
69056929

69066930
/**
6907-
* ### .increasesButNotBy(function, object, property, [message])
6931+
* ### .increasesButNotBy(function, object, property, delta, [message])
69086932
*
69096933
* Asserts that a function does not increase a numeric object property or function's return value by an amount (delta).
69106934
*
@@ -7034,7 +7058,7 @@ module.exports = function (chai, util) {
70347058
* var fn = function() { obj.val = 5 };
70357059
* assert.doesNotDecreaseBy(fn, obj, 'val', 1);
70367060
*
7037-
* @name doesNotDecrease
7061+
* @name doesNotDecreaseBy
70387062
* @param {Function} modifier function
70397063
* @param {Object} object or getter function
70407064
* @param {String} property name _optional_
@@ -8101,7 +8125,7 @@ module.exports = function getActual(obj, args) {
81018125
* inherited or not.
81028126
*
81038127
* @param {Object} object
8104-
* @returns {!Array}
8128+
* @returns {Array}
81058129
* @namespace Utils
81068130
* @name getEnumerableProperties
81078131
* @api public
@@ -8298,7 +8322,7 @@ module.exports = function getOwnEnumerablePropertySymbols(obj) {
82988322
* inherited or not.
82998323
*
83008324
* @param {Object} object
8301-
* @returns {!Array}
8325+
* @returns {Array}
83028326
* @namespace Utils
83038327
* @name getProperties
83048328
* @api public
@@ -10344,13 +10368,20 @@ function parsePath(path) {
1034410368
var str = path.replace(/([^\\])\[/g, '$1.[');
1034510369
var parts = str.match(/(\\\.|[^.]+?)+/g);
1034610370
return parts.map(function mapMatches(value) {
10371+
if (
10372+
value === 'constructor' ||
10373+
value === '__proto__' ||
10374+
value === 'prototype'
10375+
) {
10376+
return {};
10377+
}
1034710378
var regexp = /^\[(\d+)\]$/;
1034810379
var mArr = regexp.exec(value);
1034910380
var parsed = null;
1035010381
if (mArr) {
1035110382
parsed = { i: parseFloat(mArr[1]) };
1035210383
} else {
10353-
parsed = { p: value.replace(/\\([.\[\]])/g, '$1') };
10384+
parsed = { p: value.replace(/\\([.[\]])/g, '$1') };
1035410385
}
1035510386

1035610387
return parsed;
@@ -10375,7 +10406,7 @@ function parsePath(path) {
1037510406
function internalGetPathValue(obj, parsed, pathDepth) {
1037610407
var temporaryValue = obj;
1037710408
var res = null;
10378-
pathDepth = (typeof pathDepth === 'undefined' ? parsed.length : pathDepth);
10409+
pathDepth = typeof pathDepth === 'undefined' ? parsed.length : pathDepth;
1037910410

1038010411
for (var i = 0; i < pathDepth; i++) {
1038110412
var part = parsed[i];
@@ -10386,7 +10417,7 @@ function internalGetPathValue(obj, parsed, pathDepth) {
1038610417
temporaryValue = temporaryValue[part.p];
1038710418
}
1038810419

10389-
if (i === (pathDepth - 1)) {
10420+
if (i === pathDepth - 1) {
1039010421
res = temporaryValue;
1039110422
}
1039210423
}
@@ -10420,7 +10451,7 @@ function internalSetPathValue(obj, val, parsed) {
1042010451
part = parsed[i];
1042110452

1042210453
// If it's the last part of the path, we set the 'propName' value with the property name
10423-
if (i === (pathDepth - 1)) {
10454+
if (i === pathDepth - 1) {
1042410455
propName = typeof part.p === 'undefined' ? part.i : part.p;
1042510456
// Now we set the property with the name held by 'propName' on object with the desired val
1042610457
tempObj[propName] = val;
@@ -10457,7 +10488,7 @@ function internalSetPathValue(obj, val, parsed) {
1045710488
*
1045810489
* @param {Object} object
1045910490
* @param {String} path
10460-
* @returns {!Object} info
10491+
* @returns {Object} info
1046110492
* @namespace Utils
1046210493
* @name getPathInfo
1046310494
* @api public
@@ -10467,7 +10498,10 @@ function getPathInfo(obj, path) {
1046710498
var parsed = parsePath(path);
1046810499
var last = parsed[parsed.length - 1];
1046910500
var info = {
10470-
parent: parsed.length > 1 ? internalGetPathValue(obj, parsed, parsed.length - 1) : obj,
10501+
parent:
10502+
parsed.length > 1 ?
10503+
internalGetPathValue(obj, parsed, parsed.length - 1) :
10504+
obj,
1047110505
name: last.p || last.i,
1047210506
value: internalGetPathValue(obj, parsed),
1047310507
};

lib/chai.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var used = [];
1010
* Chai version
1111
*/
1212

13-
exports.version = '4.3.0';
13+
exports.version = '4.3.1';
1414

1515
/*!
1616
* Assertion Error

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"Veselin Todorov <[email protected]>",
1818
"John Firebaugh <[email protected]>"
1919
],
20-
"version": "4.3.0",
20+
"version": "4.3.1",
2121
"repository": {
2222
"type": "git",
2323
"url": "https://github.com/chaijs/chai"

0 commit comments

Comments
 (0)