chai 4.3.10 → 4.4.1
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/chai.js +49 -23
- package/lib/chai/assertion.js +3 -0
- package/lib/chai/config.js +27 -1
- package/lib/chai/core/assertions.js +19 -22
- package/package.json +1 -1
package/chai.js
CHANGED
|
@@ -150,6 +150,8 @@ module.exports = function (_chai, util) {
|
|
|
150
150
|
* from within another assertion. It's also temporarily set to `true` before
|
|
151
151
|
* an overwritten assertion gets called by the overwriting assertion.
|
|
152
152
|
*
|
|
153
|
+
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
|
|
154
|
+
*
|
|
153
155
|
* @param {Mixed} obj target of the assertion
|
|
154
156
|
* @param {String} msg (optional) custom error message
|
|
155
157
|
* @param {Function} ssfi (optional) starting point for removing stack frames
|
|
@@ -162,6 +164,7 @@ module.exports = function (_chai, util) {
|
|
|
162
164
|
flag(this, 'lockSsfi', lockSsfi);
|
|
163
165
|
flag(this, 'object', obj);
|
|
164
166
|
flag(this, 'message', msg);
|
|
167
|
+
flag(this, 'eql', config.deepEqual || util.eql);
|
|
165
168
|
|
|
166
169
|
return util.proxify(this);
|
|
167
170
|
}
|
|
@@ -365,7 +368,33 @@ module.exports = {
|
|
|
365
368
|
* @api public
|
|
366
369
|
*/
|
|
367
370
|
|
|
368
|
-
proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON']
|
|
371
|
+
proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON'],
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* ### config.deepEqual
|
|
375
|
+
*
|
|
376
|
+
* User configurable property, defines which a custom function to use for deepEqual
|
|
377
|
+
* comparisons.
|
|
378
|
+
* By default, the function used is the one from the `deep-eql` package without custom comparator.
|
|
379
|
+
*
|
|
380
|
+
* // use a custom comparator
|
|
381
|
+
* chai.config.deepEqual = (expected, actual) => {
|
|
382
|
+
* return chai.util.eql(expected, actual, {
|
|
383
|
+
* comparator: (expected, actual) => {
|
|
384
|
+
* // for non number comparison, use the default behavior
|
|
385
|
+
* if(typeof expected !== 'number') return null;
|
|
386
|
+
* // allow a difference of 10 between compared numbers
|
|
387
|
+
* return typeof actual === 'number' && Math.abs(actual - expected) < 10
|
|
388
|
+
* }
|
|
389
|
+
* })
|
|
390
|
+
* };
|
|
391
|
+
*
|
|
392
|
+
* @param {Function}
|
|
393
|
+
* @api public
|
|
394
|
+
*/
|
|
395
|
+
|
|
396
|
+
deepEqual: null
|
|
397
|
+
|
|
369
398
|
};
|
|
370
399
|
|
|
371
400
|
},{}],5:[function(require,module,exports){
|
|
@@ -849,7 +878,8 @@ module.exports = function (chai, _) {
|
|
|
849
878
|
, negate = flag(this, 'negate')
|
|
850
879
|
, ssfi = flag(this, 'ssfi')
|
|
851
880
|
, isDeep = flag(this, 'deep')
|
|
852
|
-
, descriptor = isDeep ? 'deep ' : ''
|
|
881
|
+
, descriptor = isDeep ? 'deep ' : ''
|
|
882
|
+
, isEql = isDeep ? flag(this, 'eql') : SameValueZero;
|
|
853
883
|
|
|
854
884
|
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
855
885
|
|
|
@@ -873,7 +903,6 @@ module.exports = function (chai, _) {
|
|
|
873
903
|
break;
|
|
874
904
|
|
|
875
905
|
case 'map':
|
|
876
|
-
var isEql = isDeep ? _.eql : SameValueZero;
|
|
877
906
|
obj.forEach(function (item) {
|
|
878
907
|
included = included || isEql(item, val);
|
|
879
908
|
});
|
|
@@ -882,7 +911,7 @@ module.exports = function (chai, _) {
|
|
|
882
911
|
case 'set':
|
|
883
912
|
if (isDeep) {
|
|
884
913
|
obj.forEach(function (item) {
|
|
885
|
-
included = included ||
|
|
914
|
+
included = included || isEql(item, val);
|
|
886
915
|
});
|
|
887
916
|
} else {
|
|
888
917
|
included = obj.has(val);
|
|
@@ -892,7 +921,7 @@ module.exports = function (chai, _) {
|
|
|
892
921
|
case 'array':
|
|
893
922
|
if (isDeep) {
|
|
894
923
|
included = obj.some(function (item) {
|
|
895
|
-
return
|
|
924
|
+
return isEql(item, val);
|
|
896
925
|
})
|
|
897
926
|
} else {
|
|
898
927
|
included = obj.indexOf(val) !== -1;
|
|
@@ -1464,8 +1493,9 @@ module.exports = function (chai, _) {
|
|
|
1464
1493
|
|
|
1465
1494
|
function assertEql(obj, msg) {
|
|
1466
1495
|
if (msg) flag(this, 'message', msg);
|
|
1496
|
+
var eql = flag(this, 'eql');
|
|
1467
1497
|
this.assert(
|
|
1468
|
-
|
|
1498
|
+
eql(obj, flag(this, 'object'))
|
|
1469
1499
|
, 'expected #{this} to deeply equal #{exp}'
|
|
1470
1500
|
, 'expected #{this} to not deeply equal #{exp}'
|
|
1471
1501
|
, obj
|
|
@@ -2233,7 +2263,8 @@ module.exports = function (chai, _) {
|
|
|
2233
2263
|
var isDeep = flag(this, 'deep')
|
|
2234
2264
|
, negate = flag(this, 'negate')
|
|
2235
2265
|
, pathInfo = isNested ? _.getPathInfo(obj, name) : null
|
|
2236
|
-
, value = isNested ? pathInfo.value : obj[name]
|
|
2266
|
+
, value = isNested ? pathInfo.value : obj[name]
|
|
2267
|
+
, isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2;;
|
|
2237
2268
|
|
|
2238
2269
|
var descriptor = '';
|
|
2239
2270
|
if (isDeep) descriptor += 'deep ';
|
|
@@ -2260,7 +2291,7 @@ module.exports = function (chai, _) {
|
|
|
2260
2291
|
|
|
2261
2292
|
if (arguments.length > 1) {
|
|
2262
2293
|
this.assert(
|
|
2263
|
-
hasProperty && (
|
|
2294
|
+
hasProperty && isEql(val, value)
|
|
2264
2295
|
, 'expected #{this} to have ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
|
|
2265
2296
|
, 'expected #{this} to not have ' + descriptor + _.inspect(name) + ' of #{act}'
|
|
2266
2297
|
, val
|
|
@@ -2408,9 +2439,10 @@ module.exports = function (chai, _) {
|
|
|
2408
2439
|
if (msg) flag(this, 'message', msg);
|
|
2409
2440
|
var obj = flag(this, 'object');
|
|
2410
2441
|
var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
|
|
2442
|
+
var eql = flag(this, 'eql');
|
|
2411
2443
|
if (actualDescriptor && descriptor) {
|
|
2412
2444
|
this.assert(
|
|
2413
|
-
|
|
2445
|
+
eql(descriptor, actualDescriptor)
|
|
2414
2446
|
, 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)
|
|
2415
2447
|
, 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)
|
|
2416
2448
|
, descriptor
|
|
@@ -2764,7 +2796,8 @@ module.exports = function (chai, _) {
|
|
|
2764
2796
|
var len = keys.length
|
|
2765
2797
|
, any = flag(this, 'any')
|
|
2766
2798
|
, all = flag(this, 'all')
|
|
2767
|
-
, expected = keys
|
|
2799
|
+
, expected = keys
|
|
2800
|
+
, isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2;
|
|
2768
2801
|
|
|
2769
2802
|
if (!any && !all) {
|
|
2770
2803
|
all = true;
|
|
@@ -2774,11 +2807,7 @@ module.exports = function (chai, _) {
|
|
|
2774
2807
|
if (any) {
|
|
2775
2808
|
ok = expected.some(function(expectedKey) {
|
|
2776
2809
|
return actual.some(function(actualKey) {
|
|
2777
|
-
|
|
2778
|
-
return _.eql(expectedKey, actualKey);
|
|
2779
|
-
} else {
|
|
2780
|
-
return expectedKey === actualKey;
|
|
2781
|
-
}
|
|
2810
|
+
return isEql(expectedKey, actualKey);
|
|
2782
2811
|
});
|
|
2783
2812
|
});
|
|
2784
2813
|
}
|
|
@@ -2787,11 +2816,7 @@ module.exports = function (chai, _) {
|
|
|
2787
2816
|
if (all) {
|
|
2788
2817
|
ok = expected.every(function(expectedKey) {
|
|
2789
2818
|
return actual.some(function(actualKey) {
|
|
2790
|
-
|
|
2791
|
-
return _.eql(expectedKey, actualKey);
|
|
2792
|
-
} else {
|
|
2793
|
-
return expectedKey === actualKey;
|
|
2794
|
-
}
|
|
2819
|
+
return isEql(expectedKey, actualKey);
|
|
2795
2820
|
});
|
|
2796
2821
|
});
|
|
2797
2822
|
|
|
@@ -3479,7 +3504,7 @@ module.exports = function (chai, _) {
|
|
|
3479
3504
|
failNegateMsg = 'expected #{this} to not have the same ' + subject + ' as #{exp}';
|
|
3480
3505
|
}
|
|
3481
3506
|
|
|
3482
|
-
var cmp = flag(this, 'deep') ?
|
|
3507
|
+
var cmp = flag(this, 'deep') ? flag(this, 'eql') : undefined;
|
|
3483
3508
|
|
|
3484
3509
|
this.assert(
|
|
3485
3510
|
isSubsetOf(subset, obj, cmp, contains, ordered)
|
|
@@ -3535,7 +3560,8 @@ module.exports = function (chai, _) {
|
|
|
3535
3560
|
, flagMsg = flag(this, 'message')
|
|
3536
3561
|
, ssfi = flag(this, 'ssfi')
|
|
3537
3562
|
, contains = flag(this, 'contains')
|
|
3538
|
-
, isDeep = flag(this, 'deep')
|
|
3563
|
+
, isDeep = flag(this, 'deep')
|
|
3564
|
+
, eql = flag(this, 'eql');
|
|
3539
3565
|
new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
|
|
3540
3566
|
|
|
3541
3567
|
if (contains) {
|
|
@@ -3549,7 +3575,7 @@ module.exports = function (chai, _) {
|
|
|
3549
3575
|
} else {
|
|
3550
3576
|
if (isDeep) {
|
|
3551
3577
|
this.assert(
|
|
3552
|
-
list.some(function(possibility) { return
|
|
3578
|
+
list.some(function(possibility) { return eql(expected, possibility) })
|
|
3553
3579
|
, 'expected #{this} to deeply equal one of #{exp}'
|
|
3554
3580
|
, 'expected #{this} to deeply equal one of #{exp}'
|
|
3555
3581
|
, list
|
package/lib/chai/assertion.js
CHANGED
|
@@ -52,6 +52,8 @@ module.exports = function (_chai, util) {
|
|
|
52
52
|
* from within another assertion. It's also temporarily set to `true` before
|
|
53
53
|
* an overwritten assertion gets called by the overwriting assertion.
|
|
54
54
|
*
|
|
55
|
+
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
|
|
56
|
+
*
|
|
55
57
|
* @param {Mixed} obj target of the assertion
|
|
56
58
|
* @param {String} msg (optional) custom error message
|
|
57
59
|
* @param {Function} ssfi (optional) starting point for removing stack frames
|
|
@@ -64,6 +66,7 @@ module.exports = function (_chai, util) {
|
|
|
64
66
|
flag(this, 'lockSsfi', lockSsfi);
|
|
65
67
|
flag(this, 'object', obj);
|
|
66
68
|
flag(this, 'message', msg);
|
|
69
|
+
flag(this, 'eql', config.deepEqual || util.eql);
|
|
67
70
|
|
|
68
71
|
return util.proxify(this);
|
|
69
72
|
}
|
package/lib/chai/config.js
CHANGED
|
@@ -90,5 +90,31 @@ module.exports = {
|
|
|
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
|
};
|
|
@@ -478,7 +478,8 @@ module.exports = function (chai, _) {
|
|
|
478
478
|
, negate = flag(this, 'negate')
|
|
479
479
|
, ssfi = flag(this, 'ssfi')
|
|
480
480
|
, isDeep = flag(this, 'deep')
|
|
481
|
-
, descriptor = isDeep ? 'deep ' : ''
|
|
481
|
+
, descriptor = isDeep ? 'deep ' : ''
|
|
482
|
+
, isEql = isDeep ? flag(this, 'eql') : SameValueZero;
|
|
482
483
|
|
|
483
484
|
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
484
485
|
|
|
@@ -502,7 +503,6 @@ module.exports = function (chai, _) {
|
|
|
502
503
|
break;
|
|
503
504
|
|
|
504
505
|
case 'map':
|
|
505
|
-
var isEql = isDeep ? _.eql : SameValueZero;
|
|
506
506
|
obj.forEach(function (item) {
|
|
507
507
|
included = included || isEql(item, val);
|
|
508
508
|
});
|
|
@@ -511,7 +511,7 @@ module.exports = function (chai, _) {
|
|
|
511
511
|
case 'set':
|
|
512
512
|
if (isDeep) {
|
|
513
513
|
obj.forEach(function (item) {
|
|
514
|
-
included = included ||
|
|
514
|
+
included = included || isEql(item, val);
|
|
515
515
|
});
|
|
516
516
|
} else {
|
|
517
517
|
included = obj.has(val);
|
|
@@ -521,7 +521,7 @@ module.exports = function (chai, _) {
|
|
|
521
521
|
case 'array':
|
|
522
522
|
if (isDeep) {
|
|
523
523
|
included = obj.some(function (item) {
|
|
524
|
-
return
|
|
524
|
+
return isEql(item, val);
|
|
525
525
|
})
|
|
526
526
|
} else {
|
|
527
527
|
included = obj.indexOf(val) !== -1;
|
|
@@ -1093,8 +1093,9 @@ module.exports = function (chai, _) {
|
|
|
1093
1093
|
|
|
1094
1094
|
function assertEql(obj, msg) {
|
|
1095
1095
|
if (msg) flag(this, 'message', msg);
|
|
1096
|
+
var eql = flag(this, 'eql');
|
|
1096
1097
|
this.assert(
|
|
1097
|
-
|
|
1098
|
+
eql(obj, flag(this, 'object'))
|
|
1098
1099
|
, 'expected #{this} to deeply equal #{exp}'
|
|
1099
1100
|
, 'expected #{this} to not deeply equal #{exp}'
|
|
1100
1101
|
, obj
|
|
@@ -1862,7 +1863,8 @@ module.exports = function (chai, _) {
|
|
|
1862
1863
|
var isDeep = flag(this, 'deep')
|
|
1863
1864
|
, negate = flag(this, 'negate')
|
|
1864
1865
|
, pathInfo = isNested ? _.getPathInfo(obj, name) : null
|
|
1865
|
-
, value = isNested ? pathInfo.value : obj[name]
|
|
1866
|
+
, value = isNested ? pathInfo.value : obj[name]
|
|
1867
|
+
, isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2;;
|
|
1866
1868
|
|
|
1867
1869
|
var descriptor = '';
|
|
1868
1870
|
if (isDeep) descriptor += 'deep ';
|
|
@@ -1889,7 +1891,7 @@ module.exports = function (chai, _) {
|
|
|
1889
1891
|
|
|
1890
1892
|
if (arguments.length > 1) {
|
|
1891
1893
|
this.assert(
|
|
1892
|
-
hasProperty && (
|
|
1894
|
+
hasProperty && isEql(val, value)
|
|
1893
1895
|
, 'expected #{this} to have ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
|
|
1894
1896
|
, 'expected #{this} to not have ' + descriptor + _.inspect(name) + ' of #{act}'
|
|
1895
1897
|
, val
|
|
@@ -2037,9 +2039,10 @@ module.exports = function (chai, _) {
|
|
|
2037
2039
|
if (msg) flag(this, 'message', msg);
|
|
2038
2040
|
var obj = flag(this, 'object');
|
|
2039
2041
|
var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
|
|
2042
|
+
var eql = flag(this, 'eql');
|
|
2040
2043
|
if (actualDescriptor && descriptor) {
|
|
2041
2044
|
this.assert(
|
|
2042
|
-
|
|
2045
|
+
eql(descriptor, actualDescriptor)
|
|
2043
2046
|
, 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)
|
|
2044
2047
|
, 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)
|
|
2045
2048
|
, descriptor
|
|
@@ -2393,7 +2396,8 @@ module.exports = function (chai, _) {
|
|
|
2393
2396
|
var len = keys.length
|
|
2394
2397
|
, any = flag(this, 'any')
|
|
2395
2398
|
, all = flag(this, 'all')
|
|
2396
|
-
, expected = keys
|
|
2399
|
+
, expected = keys
|
|
2400
|
+
, isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2;
|
|
2397
2401
|
|
|
2398
2402
|
if (!any && !all) {
|
|
2399
2403
|
all = true;
|
|
@@ -2403,11 +2407,7 @@ module.exports = function (chai, _) {
|
|
|
2403
2407
|
if (any) {
|
|
2404
2408
|
ok = expected.some(function(expectedKey) {
|
|
2405
2409
|
return actual.some(function(actualKey) {
|
|
2406
|
-
|
|
2407
|
-
return _.eql(expectedKey, actualKey);
|
|
2408
|
-
} else {
|
|
2409
|
-
return expectedKey === actualKey;
|
|
2410
|
-
}
|
|
2410
|
+
return isEql(expectedKey, actualKey);
|
|
2411
2411
|
});
|
|
2412
2412
|
});
|
|
2413
2413
|
}
|
|
@@ -2416,11 +2416,7 @@ module.exports = function (chai, _) {
|
|
|
2416
2416
|
if (all) {
|
|
2417
2417
|
ok = expected.every(function(expectedKey) {
|
|
2418
2418
|
return actual.some(function(actualKey) {
|
|
2419
|
-
|
|
2420
|
-
return _.eql(expectedKey, actualKey);
|
|
2421
|
-
} else {
|
|
2422
|
-
return expectedKey === actualKey;
|
|
2423
|
-
}
|
|
2419
|
+
return isEql(expectedKey, actualKey);
|
|
2424
2420
|
});
|
|
2425
2421
|
});
|
|
2426
2422
|
|
|
@@ -3108,7 +3104,7 @@ module.exports = function (chai, _) {
|
|
|
3108
3104
|
failNegateMsg = 'expected #{this} to not have the same ' + subject + ' as #{exp}';
|
|
3109
3105
|
}
|
|
3110
3106
|
|
|
3111
|
-
var cmp = flag(this, 'deep') ?
|
|
3107
|
+
var cmp = flag(this, 'deep') ? flag(this, 'eql') : undefined;
|
|
3112
3108
|
|
|
3113
3109
|
this.assert(
|
|
3114
3110
|
isSubsetOf(subset, obj, cmp, contains, ordered)
|
|
@@ -3164,7 +3160,8 @@ module.exports = function (chai, _) {
|
|
|
3164
3160
|
, flagMsg = flag(this, 'message')
|
|
3165
3161
|
, ssfi = flag(this, 'ssfi')
|
|
3166
3162
|
, contains = flag(this, 'contains')
|
|
3167
|
-
, isDeep = flag(this, 'deep')
|
|
3163
|
+
, isDeep = flag(this, 'deep')
|
|
3164
|
+
, eql = flag(this, 'eql');
|
|
3168
3165
|
new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
|
|
3169
3166
|
|
|
3170
3167
|
if (contains) {
|
|
@@ -3178,7 +3175,7 @@ module.exports = function (chai, _) {
|
|
|
3178
3175
|
} else {
|
|
3179
3176
|
if (isDeep) {
|
|
3180
3177
|
this.assert(
|
|
3181
|
-
list.some(function(possibility) { return
|
|
3178
|
+
list.some(function(possibility) { return eql(expected, possibility) })
|
|
3182
3179
|
, 'expected #{this} to deeply equal one of #{exp}'
|
|
3183
3180
|
, 'expected #{this} to deeply equal one of #{exp}'
|
|
3184
3181
|
, list
|