chai 5.0.0-alpha.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -6
- package/chai.js +1 -6
- package/lib/chai/assertion.js +3 -0
- package/lib/chai/config.js +27 -1
- package/lib/chai/core/assertions.js +19 -22
- package/lib/chai.js +0 -6
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -23,12 +23,6 @@
|
|
|
23
23
|
src="https://img.shields.io/badge/node-%3E=4.0-blue.svg?style=flat-square"
|
|
24
24
|
/>
|
|
25
25
|
</a>
|
|
26
|
-
<a href="https://codecov.io/gh/chaijs/chai">
|
|
27
|
-
<img
|
|
28
|
-
alt="coverage:?"
|
|
29
|
-
src="https://img.shields.io/codecov/c/github/chaijs/chai.svg?style=flat-square"
|
|
30
|
-
/>
|
|
31
|
-
</a>
|
|
32
26
|
<br/>
|
|
33
27
|
<a href="https://chai-slack.herokuapp.com/">
|
|
34
28
|
<img
|
package/chai.js
CHANGED
|
@@ -3676,7 +3676,6 @@ assert.isNotEmpty = function(val, msg) {
|
|
|
3676
3676
|
|
|
3677
3677
|
// lib/chai.js
|
|
3678
3678
|
var used = [];
|
|
3679
|
-
var version = "4.3.3";
|
|
3680
3679
|
function use(fn) {
|
|
3681
3680
|
const exports = {
|
|
3682
3681
|
AssertionError,
|
|
@@ -3703,8 +3702,7 @@ export {
|
|
|
3703
3702
|
expect,
|
|
3704
3703
|
should,
|
|
3705
3704
|
use,
|
|
3706
|
-
utils_exports as util
|
|
3707
|
-
version
|
|
3705
|
+
utils_exports as util
|
|
3708
3706
|
};
|
|
3709
3707
|
/*!
|
|
3710
3708
|
* Chai - flag utility
|
|
@@ -3974,9 +3972,6 @@ export {
|
|
|
3974
3972
|
/*!
|
|
3975
3973
|
* Aliases.
|
|
3976
3974
|
*/
|
|
3977
|
-
/*!
|
|
3978
|
-
* Chai version
|
|
3979
|
-
*/
|
|
3980
3975
|
/*!
|
|
3981
3976
|
* Assertion Error
|
|
3982
3977
|
*/
|
package/lib/chai/assertion.js
CHANGED
|
@@ -40,6 +40,8 @@ import * as util from './utils/index.js';
|
|
|
40
40
|
* from within another assertion. It's also temporarily set to `true` before
|
|
41
41
|
* an overwritten assertion gets called by the overwriting assertion.
|
|
42
42
|
*
|
|
43
|
+
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
|
|
44
|
+
*
|
|
43
45
|
* @param {Mixed} obj target of the assertion
|
|
44
46
|
* @param {String} msg (optional) custom error message
|
|
45
47
|
* @param {Function} ssfi (optional) starting point for removing stack frames
|
|
@@ -52,6 +54,7 @@ export function Assertion (obj, msg, ssfi, lockSsfi) {
|
|
|
52
54
|
util.flag(this, 'lockSsfi', lockSsfi);
|
|
53
55
|
util.flag(this, 'object', obj);
|
|
54
56
|
util.flag(this, 'message', msg);
|
|
57
|
+
util.flag(this, 'eql', config.deepEqual ?? util.eql);
|
|
55
58
|
|
|
56
59
|
return util.proxify(this);
|
|
57
60
|
}
|
package/lib/chai/config.js
CHANGED
|
@@ -90,5 +90,31 @@ export const config = {
|
|
|
90
90
|
* @api public
|
|
91
91
|
*/
|
|
92
92
|
|
|
93
|
-
proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON']
|
|
93
|
+
proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON'],
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* ### config.deepEqual
|
|
97
|
+
*
|
|
98
|
+
* User configurable property, defines which a custom function to use for deepEqual
|
|
99
|
+
* comparisons.
|
|
100
|
+
* By default, the function used is the one from the `deep-eql` package without custom comparator.
|
|
101
|
+
*
|
|
102
|
+
* // use a custom comparator
|
|
103
|
+
* chai.config.deepEqual = (expected, actual) => {
|
|
104
|
+
* return chai.util.eql(expected, actual, {
|
|
105
|
+
* comparator: (expected, actual) => {
|
|
106
|
+
* // for non number comparison, use the default behavior
|
|
107
|
+
* if(typeof expected !== 'number') return null;
|
|
108
|
+
* // allow a difference of 10 between compared numbers
|
|
109
|
+
* return typeof actual === 'number' && Math.abs(actual - expected) < 10
|
|
110
|
+
* }
|
|
111
|
+
* })
|
|
112
|
+
* };
|
|
113
|
+
*
|
|
114
|
+
* @param {Function}
|
|
115
|
+
* @api public
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
deepEqual: null
|
|
119
|
+
|
|
94
120
|
};
|
|
@@ -479,7 +479,8 @@ function include (val, msg) {
|
|
|
479
479
|
, negate = flag(this, 'negate')
|
|
480
480
|
, ssfi = flag(this, 'ssfi')
|
|
481
481
|
, isDeep = flag(this, 'deep')
|
|
482
|
-
, descriptor = isDeep ? 'deep ' : ''
|
|
482
|
+
, descriptor = isDeep ? 'deep ' : ''
|
|
483
|
+
, isEql = isDeep ? flag(this, 'eql') : SameValueZero;
|
|
483
484
|
|
|
484
485
|
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
485
486
|
|
|
@@ -503,7 +504,6 @@ function include (val, msg) {
|
|
|
503
504
|
break;
|
|
504
505
|
|
|
505
506
|
case 'map':
|
|
506
|
-
var isEql = isDeep ? _.eql : SameValueZero;
|
|
507
507
|
obj.forEach(function (item) {
|
|
508
508
|
included = included || isEql(item, val);
|
|
509
509
|
});
|
|
@@ -512,7 +512,7 @@ function include (val, msg) {
|
|
|
512
512
|
case 'set':
|
|
513
513
|
if (isDeep) {
|
|
514
514
|
obj.forEach(function (item) {
|
|
515
|
-
included = included ||
|
|
515
|
+
included = included || isEql(item, val);
|
|
516
516
|
});
|
|
517
517
|
} else {
|
|
518
518
|
included = obj.has(val);
|
|
@@ -522,7 +522,7 @@ function include (val, msg) {
|
|
|
522
522
|
case 'array':
|
|
523
523
|
if (isDeep) {
|
|
524
524
|
included = obj.some(function (item) {
|
|
525
|
-
return
|
|
525
|
+
return isEql(item, val);
|
|
526
526
|
})
|
|
527
527
|
} else {
|
|
528
528
|
included = obj.indexOf(val) !== -1;
|
|
@@ -1094,8 +1094,9 @@ Assertion.addMethod('eq', assertEqual);
|
|
|
1094
1094
|
|
|
1095
1095
|
function assertEql(obj, msg) {
|
|
1096
1096
|
if (msg) flag(this, 'message', msg);
|
|
1097
|
+
var eql = flag(this, 'eql');
|
|
1097
1098
|
this.assert(
|
|
1098
|
-
|
|
1099
|
+
eql(obj, flag(this, 'object'))
|
|
1099
1100
|
, 'expected #{this} to deeply equal #{exp}'
|
|
1100
1101
|
, 'expected #{this} to not deeply equal #{exp}'
|
|
1101
1102
|
, obj
|
|
@@ -1863,7 +1864,8 @@ function assertProperty (name, val, msg) {
|
|
|
1863
1864
|
var isDeep = flag(this, 'deep')
|
|
1864
1865
|
, negate = flag(this, 'negate')
|
|
1865
1866
|
, pathInfo = isNested ? _.getPathInfo(obj, name) : null
|
|
1866
|
-
, value = isNested ? pathInfo.value : obj[name]
|
|
1867
|
+
, value = isNested ? pathInfo.value : obj[name]
|
|
1868
|
+
, isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2;
|
|
1867
1869
|
|
|
1868
1870
|
var descriptor = '';
|
|
1869
1871
|
if (isDeep) descriptor += 'deep ';
|
|
@@ -1890,7 +1892,7 @@ function assertProperty (name, val, msg) {
|
|
|
1890
1892
|
|
|
1891
1893
|
if (arguments.length > 1) {
|
|
1892
1894
|
this.assert(
|
|
1893
|
-
|
|
1895
|
+
hasProperty && isEql(val, value)
|
|
1894
1896
|
, 'expected #{this} to have ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
|
|
1895
1897
|
, 'expected #{this} to not have ' + descriptor + _.inspect(name) + ' of #{act}'
|
|
1896
1898
|
, val
|
|
@@ -2038,9 +2040,10 @@ function assertOwnPropertyDescriptor (name, descriptor, msg) {
|
|
|
2038
2040
|
if (msg) flag(this, 'message', msg);
|
|
2039
2041
|
var obj = flag(this, 'object');
|
|
2040
2042
|
var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
|
|
2043
|
+
var eql = flag(this, 'eql');
|
|
2041
2044
|
if (actualDescriptor && descriptor) {
|
|
2042
2045
|
this.assert(
|
|
2043
|
-
|
|
2046
|
+
eql(descriptor, actualDescriptor)
|
|
2044
2047
|
, 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)
|
|
2045
2048
|
, 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)
|
|
2046
2049
|
, descriptor
|
|
@@ -2394,7 +2397,8 @@ function assertKeys (keys) {
|
|
|
2394
2397
|
var len = keys.length
|
|
2395
2398
|
, any = flag(this, 'any')
|
|
2396
2399
|
, all = flag(this, 'all')
|
|
2397
|
-
, expected = keys
|
|
2400
|
+
, expected = keys
|
|
2401
|
+
, isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2;
|
|
2398
2402
|
|
|
2399
2403
|
if (!any && !all) {
|
|
2400
2404
|
all = true;
|
|
@@ -2404,11 +2408,7 @@ function assertKeys (keys) {
|
|
|
2404
2408
|
if (any) {
|
|
2405
2409
|
ok = expected.some(function(expectedKey) {
|
|
2406
2410
|
return actual.some(function(actualKey) {
|
|
2407
|
-
|
|
2408
|
-
return _.eql(expectedKey, actualKey);
|
|
2409
|
-
} else {
|
|
2410
|
-
return expectedKey === actualKey;
|
|
2411
|
-
}
|
|
2411
|
+
return isEql(expectedKey, actualKey);
|
|
2412
2412
|
});
|
|
2413
2413
|
});
|
|
2414
2414
|
}
|
|
@@ -2417,11 +2417,7 @@ function assertKeys (keys) {
|
|
|
2417
2417
|
if (all) {
|
|
2418
2418
|
ok = expected.every(function(expectedKey) {
|
|
2419
2419
|
return actual.some(function(actualKey) {
|
|
2420
|
-
|
|
2421
|
-
return _.eql(expectedKey, actualKey);
|
|
2422
|
-
} else {
|
|
2423
|
-
return expectedKey === actualKey;
|
|
2424
|
-
}
|
|
2420
|
+
return isEql(expectedKey, actualKey);
|
|
2425
2421
|
});
|
|
2426
2422
|
});
|
|
2427
2423
|
|
|
@@ -3109,7 +3105,7 @@ Assertion.addMethod('members', function (subset, msg) {
|
|
|
3109
3105
|
failNegateMsg = 'expected #{this} to not have the same ' + subject + ' as #{exp}';
|
|
3110
3106
|
}
|
|
3111
3107
|
|
|
3112
|
-
var cmp = flag(this, 'deep') ?
|
|
3108
|
+
var cmp = flag(this, 'deep') ? flag(this, 'eql') : undefined;
|
|
3113
3109
|
|
|
3114
3110
|
this.assert(
|
|
3115
3111
|
isSubsetOf(subset, obj, cmp, contains, ordered)
|
|
@@ -3165,7 +3161,8 @@ function oneOf (list, msg) {
|
|
|
3165
3161
|
, flagMsg = flag(this, 'message')
|
|
3166
3162
|
, ssfi = flag(this, 'ssfi')
|
|
3167
3163
|
, contains = flag(this, 'contains')
|
|
3168
|
-
, isDeep = flag(this, 'deep')
|
|
3164
|
+
, isDeep = flag(this, 'deep')
|
|
3165
|
+
, eql = flag(this, 'eql');
|
|
3169
3166
|
new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
|
|
3170
3167
|
|
|
3171
3168
|
if (contains) {
|
|
@@ -3179,7 +3176,7 @@ function oneOf (list, msg) {
|
|
|
3179
3176
|
} else {
|
|
3180
3177
|
if (isDeep) {
|
|
3181
3178
|
this.assert(
|
|
3182
|
-
list.some(function(possibility) { return
|
|
3179
|
+
list.some(function(possibility) { return eql(expected, possibility) })
|
|
3183
3180
|
, 'expected #{this} to deeply equal one of #{exp}'
|
|
3184
3181
|
, 'expected #{this} to deeply equal one of #{exp}'
|
|
3185
3182
|
, list
|
package/lib/chai.js
CHANGED
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"Veselin Todorov <hi@vesln.com>",
|
|
19
19
|
"John Firebaugh <john.firebaugh@gmail.com>"
|
|
20
20
|
],
|
|
21
|
-
"version": "5.0.0
|
|
21
|
+
"version": "5.0.0",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
24
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"test": "npm run test-node && npm run test-chrome",
|
|
36
36
|
"test-node": "mocha --require ./test/bootstrap/index.js --reporter dot test/*.js",
|
|
37
37
|
"test-chrome": "web-test-runner --playwright",
|
|
38
|
-
"test-cov": "istanbul cover ./node_modules/.bin/_mocha -- --require ./test/bootstrap/index.js test/*.js",
|
|
39
38
|
"clean": "rm -f chai.js coverage"
|
|
40
39
|
},
|
|
41
40
|
"engines": {
|
|
@@ -54,9 +53,7 @@
|
|
|
54
53
|
"@web/test-runner": "^0.17.2",
|
|
55
54
|
"@web/test-runner-playwright": "^0.10.2",
|
|
56
55
|
"bump-cli": "^1.1.3",
|
|
57
|
-
"codecov": "^3.8.1",
|
|
58
56
|
"esbuild": "^0.17.3",
|
|
59
|
-
"istanbul": "^0.4.3",
|
|
60
57
|
"mocha": "^8.3.0"
|
|
61
58
|
}
|
|
62
59
|
}
|