chai 5.1.0 → 5.1.2
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 +3 -3
- package/chai.js +138 -79
- package/eslint.config.js +12 -0
- package/lib/chai/assertion.js +28 -28
- package/lib/chai/config.js +18 -24
- package/lib/chai/core/assertions.js +252 -255
- package/lib/chai/interface/assert.js +438 -390
- package/lib/chai/interface/expect.js +7 -2
- package/lib/chai/interface/should.js +30 -20
- package/lib/chai/utils/addChainableMethod.js +5 -6
- package/lib/chai/utils/addLengthGuard.js +3 -3
- package/lib/chai/utils/addMethod.js +5 -6
- package/lib/chai/utils/addProperty.js +5 -6
- package/lib/chai/utils/compareByInspect.js +4 -5
- package/lib/chai/utils/expectTypes.js +7 -8
- package/lib/chai/utils/flag.js +5 -5
- package/lib/chai/utils/getActual.js +3 -3
- package/lib/chai/utils/getEnumerableProperties.js +2 -3
- package/lib/chai/utils/getMessage.js +4 -4
- package/lib/chai/utils/getOperator.js +8 -4
- package/lib/chai/utils/getOwnEnumerableProperties.js +2 -3
- package/lib/chai/utils/getOwnEnumerablePropertySymbols.js +2 -3
- package/lib/chai/utils/getProperties.js +5 -3
- package/lib/chai/utils/index.js +23 -2
- package/lib/chai/utils/inspect.js +5 -4
- package/lib/chai/utils/isNaN.js +3 -3
- package/lib/chai/utils/isProxyEnabled.js +1 -1
- package/lib/chai/utils/objDisplay.js +2 -3
- package/lib/chai/utils/overwriteChainableMethod.js +7 -8
- package/lib/chai/utils/overwriteMethod.js +10 -11
- package/lib/chai/utils/overwriteProperty.js +10 -12
- package/lib/chai/utils/proxify.js +9 -9
- package/lib/chai/utils/test.js +3 -3
- package/lib/chai/utils/transferFlags.js +4 -6
- package/lib/chai/utils/type-detect.js +4 -0
- package/lib/chai.js +2 -2
- package/package.json +6 -3
- package/web-test-runner.config.js +4 -1
|
@@ -39,7 +39,7 @@ const {flag} = _;
|
|
|
39
39
|
*
|
|
40
40
|
* @name language chains
|
|
41
41
|
* @namespace BDD
|
|
42
|
-
* @
|
|
42
|
+
* @public
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
45
|
[ 'to', 'be', 'been', 'is'
|
|
@@ -69,7 +69,7 @@ const {flag} = _;
|
|
|
69
69
|
*
|
|
70
70
|
* @name not
|
|
71
71
|
* @namespace BDD
|
|
72
|
-
* @
|
|
72
|
+
* @public
|
|
73
73
|
*/
|
|
74
74
|
|
|
75
75
|
Assertion.addProperty('not', function () {
|
|
@@ -110,7 +110,7 @@ Assertion.addProperty('not', function () {
|
|
|
110
110
|
*
|
|
111
111
|
* @name deep
|
|
112
112
|
* @namespace BDD
|
|
113
|
-
* @
|
|
113
|
+
* @public
|
|
114
114
|
*/
|
|
115
115
|
|
|
116
116
|
Assertion.addProperty('deep', function () {
|
|
@@ -136,7 +136,7 @@ Assertion.addProperty('deep', function () {
|
|
|
136
136
|
*
|
|
137
137
|
* @name nested
|
|
138
138
|
* @namespace BDD
|
|
139
|
-
* @
|
|
139
|
+
* @public
|
|
140
140
|
*/
|
|
141
141
|
|
|
142
142
|
Assertion.addProperty('nested', function () {
|
|
@@ -162,7 +162,7 @@ Assertion.addProperty('nested', function () {
|
|
|
162
162
|
*
|
|
163
163
|
* @name own
|
|
164
164
|
* @namespace BDD
|
|
165
|
-
* @
|
|
165
|
+
* @public
|
|
166
166
|
*/
|
|
167
167
|
|
|
168
168
|
Assertion.addProperty('own', function () {
|
|
@@ -186,7 +186,7 @@ Assertion.addProperty('own', function () {
|
|
|
186
186
|
*
|
|
187
187
|
* @name ordered
|
|
188
188
|
* @namespace BDD
|
|
189
|
-
* @
|
|
189
|
+
* @public
|
|
190
190
|
*/
|
|
191
191
|
|
|
192
192
|
Assertion.addProperty('ordered', function () {
|
|
@@ -206,7 +206,7 @@ Assertion.addProperty('ordered', function () {
|
|
|
206
206
|
*
|
|
207
207
|
* @name any
|
|
208
208
|
* @namespace BDD
|
|
209
|
-
* @
|
|
209
|
+
* @public
|
|
210
210
|
*/
|
|
211
211
|
|
|
212
212
|
Assertion.addProperty('any', function () {
|
|
@@ -231,9 +231,8 @@ Assertion.addProperty('any', function () {
|
|
|
231
231
|
*
|
|
232
232
|
* @name all
|
|
233
233
|
* @namespace BDD
|
|
234
|
-
* @
|
|
234
|
+
* @public
|
|
235
235
|
*/
|
|
236
|
-
|
|
237
236
|
Assertion.addProperty('all', function () {
|
|
238
237
|
flag(this, 'all', true);
|
|
239
238
|
flag(this, 'any', false);
|
|
@@ -265,7 +264,7 @@ const functionTypes = {
|
|
|
265
264
|
* `.a` supports objects that have a custom type set via `Symbol.toStringTag`.
|
|
266
265
|
*
|
|
267
266
|
* var myObj = {
|
|
268
|
-
*
|
|
267
|
+
* [Symbol.toStringTag]: 'myCustomType'
|
|
269
268
|
* };
|
|
270
269
|
*
|
|
271
270
|
* expect(myObj).to.be.a('myCustomType').but.not.an('object');
|
|
@@ -300,10 +299,10 @@ const functionTypes = {
|
|
|
300
299
|
*
|
|
301
300
|
* @name a
|
|
302
301
|
* @alias an
|
|
303
|
-
* @param {
|
|
304
|
-
* @param {
|
|
302
|
+
* @param {string} type
|
|
303
|
+
* @param {string} msg _optional_
|
|
305
304
|
* @namespace BDD
|
|
306
|
-
* @
|
|
305
|
+
* @public
|
|
307
306
|
*/
|
|
308
307
|
function an (type, msg) {
|
|
309
308
|
if (msg) flag(this, 'message', msg);
|
|
@@ -331,6 +330,23 @@ function an (type, msg) {
|
|
|
331
330
|
Assertion.addChainableMethod('an', an);
|
|
332
331
|
Assertion.addChainableMethod('a', an);
|
|
333
332
|
|
|
333
|
+
/**
|
|
334
|
+
*
|
|
335
|
+
* @param {unknown} a
|
|
336
|
+
* @param {unknown} b
|
|
337
|
+
* @returns {boolean}
|
|
338
|
+
*/
|
|
339
|
+
function SameValueZero(a, b) {
|
|
340
|
+
return (_.isNaN(a) && _.isNaN(b)) || a === b;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
*
|
|
345
|
+
*/
|
|
346
|
+
function includeChainingBehavior () {
|
|
347
|
+
flag(this, 'contains', true);
|
|
348
|
+
}
|
|
349
|
+
|
|
334
350
|
/**
|
|
335
351
|
* ### .include(val[, msg])
|
|
336
352
|
*
|
|
@@ -472,20 +488,11 @@ Assertion.addChainableMethod('a', an);
|
|
|
472
488
|
* @alias contain
|
|
473
489
|
* @alias includes
|
|
474
490
|
* @alias contains
|
|
475
|
-
* @param {
|
|
476
|
-
* @param {
|
|
491
|
+
* @param {unknown} val
|
|
492
|
+
* @param {string} msg _optional_
|
|
477
493
|
* @namespace BDD
|
|
478
|
-
* @
|
|
494
|
+
* @public
|
|
479
495
|
*/
|
|
480
|
-
|
|
481
|
-
function SameValueZero(a, b) {
|
|
482
|
-
return (_.isNaN(a) && _.isNaN(b)) || a === b;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function includeChainingBehavior () {
|
|
486
|
-
flag(this, 'contains', true);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
496
|
function include (val, msg) {
|
|
490
497
|
if (msg) flag(this, 'message', msg);
|
|
491
498
|
|
|
@@ -643,9 +650,8 @@ Assertion.addChainableMethod('includes', include, includeChainingBehavior);
|
|
|
643
650
|
*
|
|
644
651
|
* @name ok
|
|
645
652
|
* @namespace BDD
|
|
646
|
-
* @
|
|
653
|
+
* @public
|
|
647
654
|
*/
|
|
648
|
-
|
|
649
655
|
Assertion.addProperty('ok', function () {
|
|
650
656
|
this.assert(
|
|
651
657
|
flag(this, 'object')
|
|
@@ -676,9 +682,8 @@ Assertion.addProperty('ok', function () {
|
|
|
676
682
|
*
|
|
677
683
|
* @name true
|
|
678
684
|
* @namespace BDD
|
|
679
|
-
* @
|
|
685
|
+
* @public
|
|
680
686
|
*/
|
|
681
|
-
|
|
682
687
|
Assertion.addProperty('true', function () {
|
|
683
688
|
this.assert(
|
|
684
689
|
true === flag(this, 'object')
|
|
@@ -688,6 +693,17 @@ Assertion.addProperty('true', function () {
|
|
|
688
693
|
);
|
|
689
694
|
});
|
|
690
695
|
|
|
696
|
+
Assertion.addProperty('numeric', function () {
|
|
697
|
+
const object = flag(this, 'object');
|
|
698
|
+
|
|
699
|
+
this.assert(
|
|
700
|
+
['Number', 'BigInt'].includes(_.type(object))
|
|
701
|
+
, 'expected #{this} to be numeric'
|
|
702
|
+
, 'expected #{this} to not be numeric'
|
|
703
|
+
, flag(this, 'negate') ? false : true
|
|
704
|
+
);
|
|
705
|
+
});
|
|
706
|
+
|
|
691
707
|
/**
|
|
692
708
|
* ### .callable
|
|
693
709
|
*
|
|
@@ -701,7 +717,7 @@ Assertion.addProperty('true', function () {
|
|
|
701
717
|
*
|
|
702
718
|
* @name callable
|
|
703
719
|
* @namespace BDD
|
|
704
|
-
* @
|
|
720
|
+
* @public
|
|
705
721
|
*/
|
|
706
722
|
Assertion.addProperty('callable', function () {
|
|
707
723
|
const val = flag(this, 'object')
|
|
@@ -748,9 +764,8 @@ Assertion.addProperty('callable', function () {
|
|
|
748
764
|
*
|
|
749
765
|
* @name false
|
|
750
766
|
* @namespace BDD
|
|
751
|
-
* @
|
|
767
|
+
* @public
|
|
752
768
|
*/
|
|
753
|
-
|
|
754
769
|
Assertion.addProperty('false', function () {
|
|
755
770
|
this.assert(
|
|
756
771
|
false === flag(this, 'object')
|
|
@@ -780,9 +795,8 @@ Assertion.addProperty('false', function () {
|
|
|
780
795
|
*
|
|
781
796
|
* @name null
|
|
782
797
|
* @namespace BDD
|
|
783
|
-
* @
|
|
798
|
+
* @public
|
|
784
799
|
*/
|
|
785
|
-
|
|
786
800
|
Assertion.addProperty('null', function () {
|
|
787
801
|
this.assert(
|
|
788
802
|
null === flag(this, 'object')
|
|
@@ -811,9 +825,8 @@ Assertion.addProperty('null', function () {
|
|
|
811
825
|
*
|
|
812
826
|
* @name undefined
|
|
813
827
|
* @namespace BDD
|
|
814
|
-
* @
|
|
828
|
+
* @public
|
|
815
829
|
*/
|
|
816
|
-
|
|
817
830
|
Assertion.addProperty('undefined', function () {
|
|
818
831
|
this.assert(
|
|
819
832
|
undefined === flag(this, 'object')
|
|
@@ -842,9 +855,8 @@ Assertion.addProperty('undefined', function () {
|
|
|
842
855
|
*
|
|
843
856
|
* @name NaN
|
|
844
857
|
* @namespace BDD
|
|
845
|
-
* @
|
|
858
|
+
* @public
|
|
846
859
|
*/
|
|
847
|
-
|
|
848
860
|
Assertion.addProperty('NaN', function () {
|
|
849
861
|
this.assert(
|
|
850
862
|
_.isNaN(flag(this, 'object'))
|
|
@@ -883,9 +895,8 @@ Assertion.addProperty('NaN', function () {
|
|
|
883
895
|
* @name exist
|
|
884
896
|
* @alias exists
|
|
885
897
|
* @namespace BDD
|
|
886
|
-
* @
|
|
898
|
+
* @public
|
|
887
899
|
*/
|
|
888
|
-
|
|
889
900
|
function assertExist () {
|
|
890
901
|
var val = flag(this, 'object');
|
|
891
902
|
this.assert(
|
|
@@ -944,9 +955,8 @@ Assertion.addProperty('exists', assertExist);
|
|
|
944
955
|
*
|
|
945
956
|
* @name empty
|
|
946
957
|
* @namespace BDD
|
|
947
|
-
* @
|
|
958
|
+
* @public
|
|
948
959
|
*/
|
|
949
|
-
|
|
950
960
|
Assertion.addProperty('empty', function () {
|
|
951
961
|
var val = flag(this, 'object')
|
|
952
962
|
, ssfi = flag(this, 'ssfi')
|
|
@@ -998,7 +1008,7 @@ Assertion.addProperty('empty', function () {
|
|
|
998
1008
|
* Asserts that the target is an `arguments` object.
|
|
999
1009
|
*
|
|
1000
1010
|
* function test () {
|
|
1001
|
-
*
|
|
1011
|
+
* expect(arguments).to.be.arguments;
|
|
1002
1012
|
* }
|
|
1003
1013
|
*
|
|
1004
1014
|
* test();
|
|
@@ -1019,9 +1029,8 @@ Assertion.addProperty('empty', function () {
|
|
|
1019
1029
|
* @name arguments
|
|
1020
1030
|
* @alias Arguments
|
|
1021
1031
|
* @namespace BDD
|
|
1022
|
-
* @
|
|
1032
|
+
* @public
|
|
1023
1033
|
*/
|
|
1024
|
-
|
|
1025
1034
|
function checkArguments () {
|
|
1026
1035
|
var obj = flag(this, 'object')
|
|
1027
1036
|
, type = _.type(obj);
|
|
@@ -1074,12 +1083,11 @@ Assertion.addProperty('Arguments', checkArguments);
|
|
|
1074
1083
|
* @name equal
|
|
1075
1084
|
* @alias equals
|
|
1076
1085
|
* @alias eq
|
|
1077
|
-
* @param {
|
|
1078
|
-
* @param {
|
|
1086
|
+
* @param {unknown} val
|
|
1087
|
+
* @param {string} msg _optional_
|
|
1079
1088
|
* @namespace BDD
|
|
1080
|
-
* @
|
|
1089
|
+
* @public
|
|
1081
1090
|
*/
|
|
1082
|
-
|
|
1083
1091
|
function assertEqual (val, msg) {
|
|
1084
1092
|
if (msg) flag(this, 'message', msg);
|
|
1085
1093
|
var obj = flag(this, 'object');
|
|
@@ -1139,12 +1147,11 @@ Assertion.addMethod('eq', assertEqual);
|
|
|
1139
1147
|
*
|
|
1140
1148
|
* @name eql
|
|
1141
1149
|
* @alias eqls
|
|
1142
|
-
* @param {
|
|
1143
|
-
* @param {
|
|
1150
|
+
* @param {unknown} obj
|
|
1151
|
+
* @param {string} msg _optional_
|
|
1144
1152
|
* @namespace BDD
|
|
1145
|
-
* @
|
|
1153
|
+
* @public
|
|
1146
1154
|
*/
|
|
1147
|
-
|
|
1148
1155
|
function assertEql(obj, msg) {
|
|
1149
1156
|
if (msg) flag(this, 'message', msg);
|
|
1150
1157
|
var eql = flag(this, 'eql');
|
|
@@ -1198,12 +1205,11 @@ Assertion.addMethod('eqls', assertEql);
|
|
|
1198
1205
|
* @name above
|
|
1199
1206
|
* @alias gt
|
|
1200
1207
|
* @alias greaterThan
|
|
1201
|
-
* @param {
|
|
1202
|
-
* @param {
|
|
1208
|
+
* @param {number} n
|
|
1209
|
+
* @param {string} msg _optional_
|
|
1203
1210
|
* @namespace BDD
|
|
1204
|
-
* @
|
|
1211
|
+
* @public
|
|
1205
1212
|
*/
|
|
1206
|
-
|
|
1207
1213
|
function assertAbove (n, msg) {
|
|
1208
1214
|
if (msg) flag(this, 'message', msg);
|
|
1209
1215
|
var obj = flag(this, 'object')
|
|
@@ -1212,27 +1218,19 @@ function assertAbove (n, msg) {
|
|
|
1212
1218
|
, msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
|
|
1213
1219
|
, ssfi = flag(this, 'ssfi')
|
|
1214
1220
|
, objType = _.type(obj).toLowerCase()
|
|
1215
|
-
, nType = _.type(n).toLowerCase()
|
|
1216
|
-
, errorMessage
|
|
1217
|
-
, shouldThrow = true;
|
|
1221
|
+
, nType = _.type(n).toLowerCase();
|
|
1218
1222
|
|
|
1219
1223
|
if (doLength && objType !== 'map' && objType !== 'set') {
|
|
1220
1224
|
new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
|
|
1221
1225
|
}
|
|
1222
1226
|
|
|
1223
1227
|
if (!doLength && (objType === 'date' && nType !== 'date')) {
|
|
1224
|
-
|
|
1225
|
-
} else if (
|
|
1226
|
-
|
|
1227
|
-
} else if (!doLength && (objType !== 'date' &&
|
|
1228
|
+
throw new AssertionError(msgPrefix + 'the argument to above must be a date', undefined, ssfi);
|
|
1229
|
+
} else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) {
|
|
1230
|
+
throw new AssertionError(msgPrefix + 'the argument to above must be a number', undefined, ssfi);
|
|
1231
|
+
} else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) {
|
|
1228
1232
|
var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
|
|
1229
|
-
|
|
1230
|
-
} else {
|
|
1231
|
-
shouldThrow = false;
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
if (shouldThrow) {
|
|
1235
|
-
throw new AssertionError(errorMessage, undefined, ssfi);
|
|
1233
|
+
throw new AssertionError(msgPrefix + 'expected ' + printObj + ' to be a number or a date', undefined, ssfi);
|
|
1236
1234
|
}
|
|
1237
1235
|
|
|
1238
1236
|
if (doLength) {
|
|
@@ -1303,12 +1301,11 @@ Assertion.addMethod('greaterThan', assertAbove);
|
|
|
1303
1301
|
* @name least
|
|
1304
1302
|
* @alias gte
|
|
1305
1303
|
* @alias greaterThanOrEqual
|
|
1306
|
-
* @param {
|
|
1307
|
-
* @param {
|
|
1304
|
+
* @param {unknown} n
|
|
1305
|
+
* @param {string} msg _optional_
|
|
1308
1306
|
* @namespace BDD
|
|
1309
|
-
* @
|
|
1307
|
+
* @public
|
|
1310
1308
|
*/
|
|
1311
|
-
|
|
1312
1309
|
function assertLeast (n, msg) {
|
|
1313
1310
|
if (msg) flag(this, 'message', msg);
|
|
1314
1311
|
var obj = flag(this, 'object')
|
|
@@ -1327,9 +1324,9 @@ function assertLeast (n, msg) {
|
|
|
1327
1324
|
|
|
1328
1325
|
if (!doLength && (objType === 'date' && nType !== 'date')) {
|
|
1329
1326
|
errorMessage = msgPrefix + 'the argument to least must be a date';
|
|
1330
|
-
} else if (
|
|
1327
|
+
} else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) {
|
|
1331
1328
|
errorMessage = msgPrefix + 'the argument to least must be a number';
|
|
1332
|
-
} else if (!doLength && (objType !== 'date' &&
|
|
1329
|
+
} else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) {
|
|
1333
1330
|
var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
|
|
1334
1331
|
errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
|
|
1335
1332
|
} else {
|
|
@@ -1407,12 +1404,11 @@ Assertion.addMethod('greaterThanOrEqual', assertLeast);
|
|
|
1407
1404
|
* @name below
|
|
1408
1405
|
* @alias lt
|
|
1409
1406
|
* @alias lessThan
|
|
1410
|
-
* @param {
|
|
1411
|
-
* @param {
|
|
1407
|
+
* @param {unknown} n
|
|
1408
|
+
* @param {string} msg _optional_
|
|
1412
1409
|
* @namespace BDD
|
|
1413
|
-
* @
|
|
1410
|
+
* @public
|
|
1414
1411
|
*/
|
|
1415
|
-
|
|
1416
1412
|
function assertBelow (n, msg) {
|
|
1417
1413
|
if (msg) flag(this, 'message', msg);
|
|
1418
1414
|
var obj = flag(this, 'object')
|
|
@@ -1428,12 +1424,12 @@ function assertBelow (n, msg) {
|
|
|
1428
1424
|
if (doLength && objType !== 'map' && objType !== 'set') {
|
|
1429
1425
|
new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
|
|
1430
1426
|
}
|
|
1431
|
-
|
|
1427
|
+
|
|
1432
1428
|
if (!doLength && (objType === 'date' && nType !== 'date')) {
|
|
1433
1429
|
errorMessage = msgPrefix + 'the argument to below must be a date';
|
|
1434
|
-
} else if (
|
|
1430
|
+
} else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) {
|
|
1435
1431
|
errorMessage = msgPrefix + 'the argument to below must be a number';
|
|
1436
|
-
} else if (!doLength && (objType !== 'date' &&
|
|
1432
|
+
} else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) {
|
|
1437
1433
|
var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
|
|
1438
1434
|
errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
|
|
1439
1435
|
} else {
|
|
@@ -1512,12 +1508,11 @@ Assertion.addMethod('lessThan', assertBelow);
|
|
|
1512
1508
|
* @name most
|
|
1513
1509
|
* @alias lte
|
|
1514
1510
|
* @alias lessThanOrEqual
|
|
1515
|
-
* @param {
|
|
1516
|
-
* @param {
|
|
1511
|
+
* @param {unknown} n
|
|
1512
|
+
* @param {string} msg _optional_
|
|
1517
1513
|
* @namespace BDD
|
|
1518
|
-
* @
|
|
1514
|
+
* @public
|
|
1519
1515
|
*/
|
|
1520
|
-
|
|
1521
1516
|
function assertMost (n, msg) {
|
|
1522
1517
|
if (msg) flag(this, 'message', msg);
|
|
1523
1518
|
var obj = flag(this, 'object')
|
|
@@ -1536,9 +1531,9 @@ function assertMost (n, msg) {
|
|
|
1536
1531
|
|
|
1537
1532
|
if (!doLength && (objType === 'date' && nType !== 'date')) {
|
|
1538
1533
|
errorMessage = msgPrefix + 'the argument to most must be a date';
|
|
1539
|
-
} else if (
|
|
1534
|
+
} else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) {
|
|
1540
1535
|
errorMessage = msgPrefix + 'the argument to most must be a number';
|
|
1541
|
-
} else if (!doLength && (objType !== 'date' &&
|
|
1536
|
+
} else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) {
|
|
1542
1537
|
var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
|
|
1543
1538
|
errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
|
|
1544
1539
|
} else {
|
|
@@ -1615,13 +1610,12 @@ Assertion.addMethod('lessThanOrEqual', assertMost);
|
|
|
1615
1610
|
* expect(4, 'nooo why fail??').to.be.within(1, 3);
|
|
1616
1611
|
*
|
|
1617
1612
|
* @name within
|
|
1618
|
-
* @param {
|
|
1619
|
-
* @param {
|
|
1620
|
-
* @param {
|
|
1613
|
+
* @param {unknown} start lower bound inclusive
|
|
1614
|
+
* @param {unknown} finish upper bound inclusive
|
|
1615
|
+
* @param {string} msg _optional_
|
|
1621
1616
|
* @namespace BDD
|
|
1622
|
-
* @
|
|
1617
|
+
* @public
|
|
1623
1618
|
*/
|
|
1624
|
-
|
|
1625
1619
|
Assertion.addMethod('within', function (start, finish, msg) {
|
|
1626
1620
|
if (msg) flag(this, 'message', msg);
|
|
1627
1621
|
var obj = flag(this, 'object')
|
|
@@ -1644,9 +1638,9 @@ Assertion.addMethod('within', function (start, finish, msg) {
|
|
|
1644
1638
|
|
|
1645
1639
|
if (!doLength && (objType === 'date' && (startType !== 'date' || finishType !== 'date'))) {
|
|
1646
1640
|
errorMessage = msgPrefix + 'the arguments to within must be dates';
|
|
1647
|
-
} else if ((
|
|
1641
|
+
} else if ((!_.isNumeric(start) || !_.isNumeric(finish)) && (doLength || _.isNumeric(obj))) {
|
|
1648
1642
|
errorMessage = msgPrefix + 'the arguments to within must be numbers';
|
|
1649
|
-
} else if (!doLength && (objType !== 'date' &&
|
|
1643
|
+
} else if (!doLength && (objType !== 'date' && !_.isNumeric(obj))) {
|
|
1650
1644
|
var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
|
|
1651
1645
|
errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
|
|
1652
1646
|
} else {
|
|
@@ -1712,13 +1706,12 @@ Assertion.addMethod('within', function (start, finish, msg) {
|
|
|
1712
1706
|
* The alias `.instanceOf` can be used interchangeably with `.instanceof`.
|
|
1713
1707
|
*
|
|
1714
1708
|
* @name instanceof
|
|
1715
|
-
* @param {
|
|
1716
|
-
* @param {
|
|
1709
|
+
* @param {unknown} constructor
|
|
1710
|
+
* @param {string} msg _optional_
|
|
1717
1711
|
* @alias instanceOf
|
|
1718
1712
|
* @namespace BDD
|
|
1719
|
-
* @
|
|
1713
|
+
* @public
|
|
1720
1714
|
*/
|
|
1721
|
-
|
|
1722
1715
|
function assertInstanceOf (constructor, msg) {
|
|
1723
1716
|
if (msg) flag(this, 'message', msg);
|
|
1724
1717
|
|
|
@@ -1860,14 +1853,12 @@ Assertion.addMethod('instanceOf', assertInstanceOf);
|
|
|
1860
1853
|
* interchangeably with `.own.property`.
|
|
1861
1854
|
*
|
|
1862
1855
|
* @name property
|
|
1863
|
-
* @param {
|
|
1864
|
-
* @param {
|
|
1865
|
-
* @param {
|
|
1866
|
-
* @returns value of property for chaining
|
|
1856
|
+
* @param {string} name
|
|
1857
|
+
* @param {unknown} val (optional)
|
|
1858
|
+
* @param {string} msg _optional_
|
|
1867
1859
|
* @namespace BDD
|
|
1868
|
-
* @
|
|
1860
|
+
* @public
|
|
1869
1861
|
*/
|
|
1870
|
-
|
|
1871
1862
|
function assertProperty (name, val, msg) {
|
|
1872
1863
|
if (msg) flag(this, 'message', msg);
|
|
1873
1864
|
|
|
@@ -1958,6 +1949,12 @@ function assertProperty (name, val, msg) {
|
|
|
1958
1949
|
|
|
1959
1950
|
Assertion.addMethod('property', assertProperty);
|
|
1960
1951
|
|
|
1952
|
+
/**
|
|
1953
|
+
*
|
|
1954
|
+
* @param {unknown} name
|
|
1955
|
+
* @param {unknown} value
|
|
1956
|
+
* @param {string} msg
|
|
1957
|
+
*/
|
|
1961
1958
|
function assertOwnProperty (name, value, msg) {
|
|
1962
1959
|
flag(this, 'own', true);
|
|
1963
1960
|
assertProperty.apply(this, arguments);
|
|
@@ -1981,10 +1978,10 @@ Assertion.addMethod('haveOwnProperty', assertOwnProperty);
|
|
|
1981
1978
|
* https://github.com/chaijs/deep-eql.
|
|
1982
1979
|
*
|
|
1983
1980
|
* expect({a: 1}).to.have.ownPropertyDescriptor('a', {
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1986
|
-
*
|
|
1987
|
-
*
|
|
1981
|
+
* configurable: true,
|
|
1982
|
+
* enumerable: true,
|
|
1983
|
+
* writable: true,
|
|
1984
|
+
* value: 1,
|
|
1988
1985
|
* });
|
|
1989
1986
|
*
|
|
1990
1987
|
* Add `.not` earlier in the chain to negate `.ownPropertyDescriptor`.
|
|
@@ -2007,10 +2004,10 @@ Assertion.addMethod('haveOwnProperty', assertOwnProperty);
|
|
|
2007
2004
|
*
|
|
2008
2005
|
* // Not recommended
|
|
2009
2006
|
* expect({b: 2}).to.not.have.ownPropertyDescriptor('a', {
|
|
2010
|
-
*
|
|
2011
|
-
*
|
|
2012
|
-
*
|
|
2013
|
-
*
|
|
2007
|
+
* configurable: true,
|
|
2008
|
+
* enumerable: true,
|
|
2009
|
+
* writable: true,
|
|
2010
|
+
* value: 1,
|
|
2014
2011
|
* });
|
|
2015
2012
|
*
|
|
2016
2013
|
* When the target is expected to have a property descriptor with the given
|
|
@@ -2020,18 +2017,18 @@ Assertion.addMethod('haveOwnProperty', assertOwnProperty);
|
|
|
2020
2017
|
*
|
|
2021
2018
|
* // Recommended
|
|
2022
2019
|
* expect({a: 3}).to.have.ownPropertyDescriptor('a', {
|
|
2023
|
-
*
|
|
2024
|
-
*
|
|
2025
|
-
*
|
|
2026
|
-
*
|
|
2020
|
+
* configurable: true,
|
|
2021
|
+
* enumerable: true,
|
|
2022
|
+
* writable: true,
|
|
2023
|
+
* value: 3,
|
|
2027
2024
|
* });
|
|
2028
2025
|
*
|
|
2029
2026
|
* // Not recommended
|
|
2030
2027
|
* expect({a: 3}).to.not.have.ownPropertyDescriptor('a', {
|
|
2031
|
-
*
|
|
2032
|
-
*
|
|
2033
|
-
*
|
|
2034
|
-
*
|
|
2028
|
+
* configurable: true,
|
|
2029
|
+
* enumerable: true,
|
|
2030
|
+
* writable: true,
|
|
2031
|
+
* value: 1,
|
|
2035
2032
|
* });
|
|
2036
2033
|
*
|
|
2037
2034
|
* `.ownPropertyDescriptor` changes the target of any assertions that follow
|
|
@@ -2048,18 +2045,18 @@ Assertion.addMethod('haveOwnProperty', assertOwnProperty);
|
|
|
2048
2045
|
*
|
|
2049
2046
|
* // Recommended
|
|
2050
2047
|
* expect({a: 1}).to.have.ownPropertyDescriptor('a', {
|
|
2051
|
-
*
|
|
2052
|
-
*
|
|
2053
|
-
*
|
|
2054
|
-
*
|
|
2048
|
+
* configurable: true,
|
|
2049
|
+
* enumerable: true,
|
|
2050
|
+
* writable: true,
|
|
2051
|
+
* value: 2,
|
|
2055
2052
|
* }, 'nooo why fail??');
|
|
2056
2053
|
*
|
|
2057
2054
|
* // Recommended
|
|
2058
2055
|
* expect({a: 1}, 'nooo why fail??').to.have.ownPropertyDescriptor('a', {
|
|
2059
|
-
*
|
|
2060
|
-
*
|
|
2061
|
-
*
|
|
2062
|
-
*
|
|
2056
|
+
* configurable: true,
|
|
2057
|
+
* enumerable: true,
|
|
2058
|
+
* writable: true,
|
|
2059
|
+
* value: 2,
|
|
2063
2060
|
* });
|
|
2064
2061
|
*
|
|
2065
2062
|
* // Recommended
|
|
@@ -2078,13 +2075,12 @@ Assertion.addMethod('haveOwnProperty', assertOwnProperty);
|
|
|
2078
2075
|
*
|
|
2079
2076
|
* @name ownPropertyDescriptor
|
|
2080
2077
|
* @alias haveOwnPropertyDescriptor
|
|
2081
|
-
* @param {
|
|
2082
|
-
* @param {
|
|
2083
|
-
* @param {
|
|
2078
|
+
* @param {string} name
|
|
2079
|
+
* @param {object} descriptor _optional_
|
|
2080
|
+
* @param {string} msg _optional_
|
|
2084
2081
|
* @namespace BDD
|
|
2085
|
-
* @
|
|
2082
|
+
* @public
|
|
2086
2083
|
*/
|
|
2087
|
-
|
|
2088
2084
|
function assertOwnPropertyDescriptor (name, descriptor, msg) {
|
|
2089
2085
|
if (typeof descriptor === 'string') {
|
|
2090
2086
|
msg = descriptor;
|
|
@@ -2116,6 +2112,13 @@ function assertOwnPropertyDescriptor (name, descriptor, msg) {
|
|
|
2116
2112
|
Assertion.addMethod('ownPropertyDescriptor', assertOwnPropertyDescriptor);
|
|
2117
2113
|
Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
|
|
2118
2114
|
|
|
2115
|
+
/**
|
|
2116
|
+
*
|
|
2117
|
+
*/
|
|
2118
|
+
function assertLengthChain () {
|
|
2119
|
+
flag(this, 'doLength', true);
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2119
2122
|
/**
|
|
2120
2123
|
* ### .lengthOf(n[, msg])
|
|
2121
2124
|
*
|
|
@@ -2168,16 +2171,11 @@ Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
|
|
|
2168
2171
|
*
|
|
2169
2172
|
* @name lengthOf
|
|
2170
2173
|
* @alias length
|
|
2171
|
-
* @param {
|
|
2172
|
-
* @param {
|
|
2174
|
+
* @param {number} n
|
|
2175
|
+
* @param {string} msg _optional_
|
|
2173
2176
|
* @namespace BDD
|
|
2174
|
-
* @
|
|
2177
|
+
* @public
|
|
2175
2178
|
*/
|
|
2176
|
-
|
|
2177
|
-
function assertLengthChain () {
|
|
2178
|
-
flag(this, 'doLength', true);
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
2179
|
function assertLength (n, msg) {
|
|
2182
2180
|
if (msg) flag(this, 'message', msg);
|
|
2183
2181
|
var obj = flag(this, 'object')
|
|
@@ -2233,9 +2231,9 @@ Assertion.addChainableMethod('lengthOf', assertLength, assertLengthChain);
|
|
|
2233
2231
|
* @name match
|
|
2234
2232
|
* @alias matches
|
|
2235
2233
|
* @param {RegExp} re
|
|
2236
|
-
* @param {
|
|
2234
|
+
* @param {string} msg _optional_
|
|
2237
2235
|
* @namespace BDD
|
|
2238
|
-
* @
|
|
2236
|
+
* @public
|
|
2239
2237
|
*/
|
|
2240
2238
|
function assertMatch(re, msg) {
|
|
2241
2239
|
if (msg) flag(this, 'message', msg);
|
|
@@ -2269,12 +2267,11 @@ Assertion.addMethod('matches', assertMatch);
|
|
|
2269
2267
|
* expect('foobar', 'nooo why fail??').to.have.string('taco');
|
|
2270
2268
|
*
|
|
2271
2269
|
* @name string
|
|
2272
|
-
* @param {
|
|
2273
|
-
* @param {
|
|
2270
|
+
* @param {string} str
|
|
2271
|
+
* @param {string} msg _optional_
|
|
2274
2272
|
* @namespace BDD
|
|
2275
|
-
* @
|
|
2273
|
+
* @public
|
|
2276
2274
|
*/
|
|
2277
|
-
|
|
2278
2275
|
Assertion.addMethod('string', function (str, msg) {
|
|
2279
2276
|
if (msg) flag(this, 'message', msg);
|
|
2280
2277
|
var obj = flag(this, 'object')
|
|
@@ -2388,11 +2385,10 @@ Assertion.addMethod('string', function (str, msg) {
|
|
|
2388
2385
|
*
|
|
2389
2386
|
* @name keys
|
|
2390
2387
|
* @alias key
|
|
2391
|
-
* @param {...
|
|
2388
|
+
* @param {...string | Array | object} keys
|
|
2392
2389
|
* @namespace BDD
|
|
2393
|
-
* @
|
|
2390
|
+
* @public
|
|
2394
2391
|
*/
|
|
2395
|
-
|
|
2396
2392
|
function assertKeys (keys) {
|
|
2397
2393
|
var obj = flag(this, 'object')
|
|
2398
2394
|
, objType = _.type(obj)
|
|
@@ -2522,7 +2518,6 @@ Assertion.addMethod('key', assertKeys);
|
|
|
2522
2518
|
* asserts that an error is thrown.
|
|
2523
2519
|
*
|
|
2524
2520
|
* var badFn = function () { throw new TypeError('Illegal salmon!'); };
|
|
2525
|
-
*
|
|
2526
2521
|
* expect(badFn).to.throw();
|
|
2527
2522
|
*
|
|
2528
2523
|
* When one argument is provided, and it's an error constructor, `.throw`
|
|
@@ -2530,7 +2525,6 @@ Assertion.addMethod('key', assertKeys);
|
|
|
2530
2525
|
* instance of that error constructor.
|
|
2531
2526
|
*
|
|
2532
2527
|
* var badFn = function () { throw new TypeError('Illegal salmon!'); };
|
|
2533
|
-
*
|
|
2534
2528
|
* expect(badFn).to.throw(TypeError);
|
|
2535
2529
|
*
|
|
2536
2530
|
* When one argument is provided, and it's an error instance, `.throw` invokes
|
|
@@ -2547,7 +2541,6 @@ Assertion.addMethod('key', assertKeys);
|
|
|
2547
2541
|
* contains that string.
|
|
2548
2542
|
*
|
|
2549
2543
|
* var badFn = function () { throw new TypeError('Illegal salmon!'); };
|
|
2550
|
-
*
|
|
2551
2544
|
* expect(badFn).to.throw('salmon');
|
|
2552
2545
|
*
|
|
2553
2546
|
* When one argument is provided, and it's a regular expression, `.throw`
|
|
@@ -2555,7 +2548,6 @@ Assertion.addMethod('key', assertKeys);
|
|
|
2555
2548
|
* message that matches that regular expression.
|
|
2556
2549
|
*
|
|
2557
2550
|
* var badFn = function () { throw new TypeError('Illegal salmon!'); };
|
|
2558
|
-
*
|
|
2559
2551
|
* expect(badFn).to.throw(/salmon/);
|
|
2560
2552
|
*
|
|
2561
2553
|
* When two arguments are provided, and the first is an error instance or
|
|
@@ -2574,7 +2566,6 @@ Assertion.addMethod('key', assertKeys);
|
|
|
2574
2566
|
* Add `.not` earlier in the chain to negate `.throw`.
|
|
2575
2567
|
*
|
|
2576
2568
|
* var goodFn = function () {};
|
|
2577
|
-
*
|
|
2578
2569
|
* expect(goodFn).to.not.throw();
|
|
2579
2570
|
*
|
|
2580
2571
|
* However, it's dangerous to negate `.throw` when providing any arguments.
|
|
@@ -2671,15 +2662,14 @@ Assertion.addMethod('key', assertKeys);
|
|
|
2671
2662
|
* @name throw
|
|
2672
2663
|
* @alias throws
|
|
2673
2664
|
* @alias Throw
|
|
2674
|
-
* @param {Error
|
|
2675
|
-
* @param {
|
|
2676
|
-
* @param {
|
|
2665
|
+
* @param {Error} errorLike
|
|
2666
|
+
* @param {string | RegExp} errMsgMatcher error message
|
|
2667
|
+
* @param {string} msg _optional_
|
|
2677
2668
|
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
|
2678
|
-
* @returns error for chaining (null if no error)
|
|
2669
|
+
* @returns {void} error for chaining (null if no error)
|
|
2679
2670
|
* @namespace BDD
|
|
2680
|
-
* @
|
|
2671
|
+
* @public
|
|
2681
2672
|
*/
|
|
2682
|
-
|
|
2683
2673
|
function assertThrows (errorLike, errMsgMatcher, msg) {
|
|
2684
2674
|
if (msg) flag(this, 'message', msg);
|
|
2685
2675
|
var obj = flag(this, 'object')
|
|
@@ -2688,15 +2678,17 @@ function assertThrows (errorLike, errMsgMatcher, msg) {
|
|
|
2688
2678
|
, negate = flag(this, 'negate') || false;
|
|
2689
2679
|
new Assertion(obj, flagMsg, ssfi, true).is.a('function');
|
|
2690
2680
|
|
|
2691
|
-
if (errorLike
|
|
2681
|
+
if (_.isRegExp(errorLike) || typeof errorLike === 'string') {
|
|
2692
2682
|
errMsgMatcher = errorLike;
|
|
2693
2683
|
errorLike = null;
|
|
2694
2684
|
}
|
|
2695
2685
|
|
|
2696
|
-
|
|
2686
|
+
let caughtErr;
|
|
2687
|
+
let errorWasThrown = false;
|
|
2697
2688
|
try {
|
|
2698
2689
|
obj();
|
|
2699
2690
|
} catch (err) {
|
|
2691
|
+
errorWasThrown = true;
|
|
2700
2692
|
caughtErr = err;
|
|
2701
2693
|
}
|
|
2702
2694
|
|
|
@@ -2720,14 +2712,26 @@ function assertThrows (errorLike, errMsgMatcher, msg) {
|
|
|
2720
2712
|
errorLikeString = _.checkError.getConstructorName(errorLike);
|
|
2721
2713
|
}
|
|
2722
2714
|
|
|
2715
|
+
let actual = caughtErr;
|
|
2716
|
+
if (caughtErr instanceof Error) {
|
|
2717
|
+
actual = caughtErr.toString();
|
|
2718
|
+
} else if (typeof caughtErr === 'string') {
|
|
2719
|
+
actual = caughtErr;
|
|
2720
|
+
} else if (caughtErr && (typeof caughtErr === 'object' || typeof caughtErr === 'function')) {
|
|
2721
|
+
try {
|
|
2722
|
+
actual = _.checkError.getConstructorName(caughtErr);
|
|
2723
|
+
} catch (_err) {
|
|
2724
|
+
// somehow wasn't a constructor, maybe we got a function thrown
|
|
2725
|
+
// or similar
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
|
|
2723
2729
|
this.assert(
|
|
2724
|
-
|
|
2730
|
+
errorWasThrown
|
|
2725
2731
|
, 'expected #{this} to throw ' + errorLikeString
|
|
2726
2732
|
, 'expected #{this} to not throw an error but #{act} was thrown'
|
|
2727
2733
|
, errorLike && errorLike.toString()
|
|
2728
|
-
,
|
|
2729
|
-
caughtErr.toString() : (typeof caughtErr === 'string' ? caughtErr : caughtErr &&
|
|
2730
|
-
_.checkError.getConstructorName(caughtErr)))
|
|
2734
|
+
, actual
|
|
2731
2735
|
);
|
|
2732
2736
|
}
|
|
2733
2737
|
|
|
@@ -2772,7 +2776,7 @@ function assertThrows (errorLike, errMsgMatcher, msg) {
|
|
|
2772
2776
|
if (caughtErr && errMsgMatcher !== undefined && errMsgMatcher !== null) {
|
|
2773
2777
|
// Here we check compatible messages
|
|
2774
2778
|
var placeholder = 'including';
|
|
2775
|
-
if (errMsgMatcher
|
|
2779
|
+
if (_.isRegExp(errMsgMatcher)) {
|
|
2776
2780
|
placeholder = 'matching'
|
|
2777
2781
|
}
|
|
2778
2782
|
|
|
@@ -2869,12 +2873,11 @@ Assertion.addMethod('Throw', assertThrows);
|
|
|
2869
2873
|
*
|
|
2870
2874
|
* @name respondTo
|
|
2871
2875
|
* @alias respondsTo
|
|
2872
|
-
* @param {
|
|
2873
|
-
* @param {
|
|
2876
|
+
* @param {string} method
|
|
2877
|
+
* @param {string} msg _optional_
|
|
2874
2878
|
* @namespace BDD
|
|
2875
|
-
* @
|
|
2879
|
+
* @public
|
|
2876
2880
|
*/
|
|
2877
|
-
|
|
2878
2881
|
function respondTo (method, msg) {
|
|
2879
2882
|
if (msg) flag(this, 'message', msg);
|
|
2880
2883
|
var obj = flag(this, 'object')
|
|
@@ -2910,9 +2913,8 @@ Assertion.addMethod('respondsTo', respondTo);
|
|
|
2910
2913
|
*
|
|
2911
2914
|
* @name itself
|
|
2912
2915
|
* @namespace BDD
|
|
2913
|
-
* @
|
|
2916
|
+
* @public
|
|
2914
2917
|
*/
|
|
2915
|
-
|
|
2916
2918
|
Assertion.addProperty('itself', function () {
|
|
2917
2919
|
flag(this, 'itself', true);
|
|
2918
2920
|
});
|
|
@@ -2924,13 +2926,13 @@ Assertion.addProperty('itself', function () {
|
|
|
2924
2926
|
* first argument, and asserts that the value returned is truthy.
|
|
2925
2927
|
*
|
|
2926
2928
|
* expect(1).to.satisfy(function(num) {
|
|
2927
|
-
*
|
|
2929
|
+
* return num > 0;
|
|
2928
2930
|
* });
|
|
2929
2931
|
*
|
|
2930
2932
|
* Add `.not` earlier in the chain to negate `.satisfy`.
|
|
2931
2933
|
*
|
|
2932
2934
|
* expect(1).to.not.satisfy(function(num) {
|
|
2933
|
-
*
|
|
2935
|
+
* return num > 2;
|
|
2934
2936
|
* });
|
|
2935
2937
|
*
|
|
2936
2938
|
* `.satisfy` accepts an optional `msg` argument which is a custom error
|
|
@@ -2938,11 +2940,11 @@ Assertion.addProperty('itself', function () {
|
|
|
2938
2940
|
* the second argument to `expect`.
|
|
2939
2941
|
*
|
|
2940
2942
|
* expect(1).to.satisfy(function(num) {
|
|
2941
|
-
*
|
|
2943
|
+
* return num > 2;
|
|
2942
2944
|
* }, 'nooo why fail??');
|
|
2943
2945
|
*
|
|
2944
2946
|
* expect(1, 'nooo why fail??').to.satisfy(function(num) {
|
|
2945
|
-
*
|
|
2947
|
+
* return num > 2;
|
|
2946
2948
|
* });
|
|
2947
2949
|
*
|
|
2948
2950
|
* The alias `.satisfies` can be used interchangeably with `.satisfy`.
|
|
@@ -2950,11 +2952,10 @@ Assertion.addProperty('itself', function () {
|
|
|
2950
2952
|
* @name satisfy
|
|
2951
2953
|
* @alias satisfies
|
|
2952
2954
|
* @param {Function} matcher
|
|
2953
|
-
* @param {
|
|
2955
|
+
* @param {string} msg _optional_
|
|
2954
2956
|
* @namespace BDD
|
|
2955
|
-
* @
|
|
2957
|
+
* @public
|
|
2956
2958
|
*/
|
|
2957
|
-
|
|
2958
2959
|
function satisfy (matcher, msg) {
|
|
2959
2960
|
if (msg) flag(this, 'message', msg);
|
|
2960
2961
|
var obj = flag(this, 'object');
|
|
@@ -3002,32 +3003,30 @@ Assertion.addMethod('satisfies', satisfy);
|
|
|
3002
3003
|
*
|
|
3003
3004
|
* @name closeTo
|
|
3004
3005
|
* @alias approximately
|
|
3005
|
-
* @param {
|
|
3006
|
-
* @param {
|
|
3007
|
-
* @param {
|
|
3006
|
+
* @param {number} expected
|
|
3007
|
+
* @param {number} delta
|
|
3008
|
+
* @param {string} msg _optional_
|
|
3008
3009
|
* @namespace BDD
|
|
3009
|
-
* @
|
|
3010
|
+
* @public
|
|
3010
3011
|
*/
|
|
3011
|
-
|
|
3012
3012
|
function closeTo(expected, delta, msg) {
|
|
3013
3013
|
if (msg) flag(this, 'message', msg);
|
|
3014
3014
|
var obj = flag(this, 'object')
|
|
3015
3015
|
, flagMsg = flag(this, 'message')
|
|
3016
3016
|
, ssfi = flag(this, 'ssfi');
|
|
3017
3017
|
|
|
3018
|
-
new Assertion(obj, flagMsg, ssfi, true).is.
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
}
|
|
3018
|
+
new Assertion(obj, flagMsg, ssfi, true).is.numeric;
|
|
3019
|
+
let message = 'A `delta` value is required for `closeTo`';
|
|
3020
|
+
if (delta == undefined) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi);
|
|
3021
|
+
new Assertion(delta, flagMsg, ssfi, true).is.numeric;
|
|
3022
|
+
message = 'A `expected` value is required for `closeTo`';
|
|
3023
|
+
if (expected == undefined) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi);
|
|
3024
|
+
new Assertion(expected, flagMsg, ssfi, true).is.numeric;
|
|
3025
|
+
|
|
3026
|
+
const abs = (x) => x < 0n ? -x : x;
|
|
3028
3027
|
|
|
3029
3028
|
this.assert(
|
|
3030
|
-
|
|
3029
|
+
abs(obj - expected) <= delta
|
|
3031
3030
|
, 'expected #{this} to be close to ' + expected + ' +/- ' + delta
|
|
3032
3031
|
, 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
|
|
3033
3032
|
);
|
|
@@ -3036,7 +3035,14 @@ function closeTo(expected, delta, msg) {
|
|
|
3036
3035
|
Assertion.addMethod('closeTo', closeTo);
|
|
3037
3036
|
Assertion.addMethod('approximately', closeTo);
|
|
3038
3037
|
|
|
3039
|
-
|
|
3038
|
+
/**
|
|
3039
|
+
* @param {unknown} _subset
|
|
3040
|
+
* @param {unknown} _superset
|
|
3041
|
+
* @param {unknown} cmp
|
|
3042
|
+
* @param {unknown} contains
|
|
3043
|
+
* @param {unknown} ordered
|
|
3044
|
+
* @returns {boolean}
|
|
3045
|
+
*/
|
|
3040
3046
|
function isSubsetOf(_subset, _superset, cmp, contains, ordered) {
|
|
3041
3047
|
let superset = Array.from(_superset);
|
|
3042
3048
|
let subset = Array.from(_subset);
|
|
@@ -3131,9 +3137,9 @@ function isSubsetOf(_subset, _superset, cmp, contains, ordered) {
|
|
|
3131
3137
|
*
|
|
3132
3138
|
* @name members
|
|
3133
3139
|
* @param {Array} set
|
|
3134
|
-
* @param {
|
|
3140
|
+
* @param {string} msg _optional_
|
|
3135
3141
|
* @namespace BDD
|
|
3136
|
-
* @
|
|
3142
|
+
* @public
|
|
3137
3143
|
*/
|
|
3138
3144
|
Assertion.addMethod('members', function (subset, msg) {
|
|
3139
3145
|
if (msg) flag(this, 'message', msg);
|
|
@@ -3190,7 +3196,7 @@ Assertion.addMethod('members', function (subset, msg) {
|
|
|
3190
3196
|
*
|
|
3191
3197
|
* @name iterable
|
|
3192
3198
|
* @namespace BDD
|
|
3193
|
-
* @
|
|
3199
|
+
* @public
|
|
3194
3200
|
*/
|
|
3195
3201
|
Assertion.addProperty('iterable', function(msg) {
|
|
3196
3202
|
if (msg) flag(this, 'message', msg);
|
|
@@ -3237,11 +3243,10 @@ Assertion.addProperty('iterable', function(msg) {
|
|
|
3237
3243
|
*
|
|
3238
3244
|
* @name oneOf
|
|
3239
3245
|
* @param {Array<*>} list
|
|
3240
|
-
* @param {
|
|
3246
|
+
* @param {string} msg _optional_
|
|
3241
3247
|
* @namespace BDD
|
|
3242
|
-
* @
|
|
3248
|
+
* @public
|
|
3243
3249
|
*/
|
|
3244
|
-
|
|
3245
3250
|
function oneOf (list, msg) {
|
|
3246
3251
|
if (msg) flag(this, 'message', msg);
|
|
3247
3252
|
var expected = flag(this, 'object')
|
|
@@ -3292,8 +3297,8 @@ Assertion.addMethod('oneOf', oneOf);
|
|
|
3292
3297
|
* to assert that `subject` is equal to its expected value.
|
|
3293
3298
|
*
|
|
3294
3299
|
* var dots = ''
|
|
3295
|
-
*
|
|
3296
|
-
*
|
|
3300
|
+
* , addDot = function () { dots += '.'; }
|
|
3301
|
+
* , getDots = function () { return dots; };
|
|
3297
3302
|
*
|
|
3298
3303
|
* // Recommended
|
|
3299
3304
|
* expect(getDots()).to.equal('');
|
|
@@ -3308,7 +3313,7 @@ Assertion.addMethod('oneOf', oneOf);
|
|
|
3308
3313
|
* target function compared to afterward.
|
|
3309
3314
|
*
|
|
3310
3315
|
* var myObj = {dots: ''}
|
|
3311
|
-
*
|
|
3316
|
+
* , addDot = function () { myObj.dots += '.'; };
|
|
3312
3317
|
*
|
|
3313
3318
|
* // Recommended
|
|
3314
3319
|
* expect(myObj).to.have.property('dots', '');
|
|
@@ -3323,13 +3328,13 @@ Assertion.addMethod('oneOf', oneOf);
|
|
|
3323
3328
|
* Add `.not` earlier in the chain to negate `.change`.
|
|
3324
3329
|
*
|
|
3325
3330
|
* var dots = ''
|
|
3326
|
-
*
|
|
3327
|
-
*
|
|
3331
|
+
* , noop = function () {}
|
|
3332
|
+
* , getDots = function () { return dots; };
|
|
3328
3333
|
*
|
|
3329
3334
|
* expect(noop).to.not.change(getDots);
|
|
3330
3335
|
*
|
|
3331
3336
|
* var myObj = {dots: ''}
|
|
3332
|
-
*
|
|
3337
|
+
* , noop = function () {};
|
|
3333
3338
|
*
|
|
3334
3339
|
* expect(noop).to.not.change(myObj, 'dots');
|
|
3335
3340
|
*
|
|
@@ -3339,13 +3344,13 @@ Assertion.addMethod('oneOf', oneOf);
|
|
|
3339
3344
|
* use the second form.
|
|
3340
3345
|
*
|
|
3341
3346
|
* var myObj = {dots: ''}
|
|
3342
|
-
*
|
|
3347
|
+
* , addDot = function () { myObj.dots += '.'; };
|
|
3343
3348
|
*
|
|
3344
3349
|
* expect(addDot).to.not.change(myObj, 'dots', 'nooo why fail??');
|
|
3345
3350
|
*
|
|
3346
3351
|
* var dots = ''
|
|
3347
|
-
*
|
|
3348
|
-
*
|
|
3352
|
+
* , addDot = function () { dots += '.'; }
|
|
3353
|
+
* , getDots = function () { return dots; };
|
|
3349
3354
|
*
|
|
3350
3355
|
* expect(addDot, 'nooo why fail??').to.not.change(getDots);
|
|
3351
3356
|
*
|
|
@@ -3358,8 +3363,8 @@ Assertion.addMethod('oneOf', oneOf);
|
|
|
3358
3363
|
* that only accepts that exact output.
|
|
3359
3364
|
*
|
|
3360
3365
|
* var myObj = {val: 1}
|
|
3361
|
-
*
|
|
3362
|
-
*
|
|
3366
|
+
* , addTwo = function () { myObj.val += 2; }
|
|
3367
|
+
* , subtractTwo = function () { myObj.val -= 2; };
|
|
3363
3368
|
*
|
|
3364
3369
|
* expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
|
|
3365
3370
|
* expect(addTwo).to.change(myObj, 'val').by(2); // Not recommended
|
|
@@ -3371,13 +3376,12 @@ Assertion.addMethod('oneOf', oneOf);
|
|
|
3371
3376
|
*
|
|
3372
3377
|
* @name change
|
|
3373
3378
|
* @alias changes
|
|
3374
|
-
* @param {
|
|
3375
|
-
* @param {
|
|
3376
|
-
* @param {
|
|
3379
|
+
* @param {string} subject
|
|
3380
|
+
* @param {string} prop name _optional_
|
|
3381
|
+
* @param {string} msg _optional_
|
|
3377
3382
|
* @namespace BDD
|
|
3378
|
-
* @
|
|
3383
|
+
* @public
|
|
3379
3384
|
*/
|
|
3380
|
-
|
|
3381
3385
|
function assertChanges (subject, prop, msg) {
|
|
3382
3386
|
if (msg) flag(this, 'message', msg);
|
|
3383
3387
|
var fn = flag(this, 'object')
|
|
@@ -3428,8 +3432,8 @@ Assertion.addMethod('changes', assertChanges);
|
|
|
3428
3432
|
* by any amount.
|
|
3429
3433
|
*
|
|
3430
3434
|
* var val = 1
|
|
3431
|
-
*
|
|
3432
|
-
*
|
|
3435
|
+
* , addTwo = function () { val += 2; }
|
|
3436
|
+
* , getVal = function () { return val; };
|
|
3433
3437
|
*
|
|
3434
3438
|
* expect(addTwo).to.increase(getVal).by(2); // Recommended
|
|
3435
3439
|
* expect(addTwo).to.increase(getVal); // Not recommended
|
|
@@ -3439,7 +3443,7 @@ Assertion.addMethod('changes', assertChanges);
|
|
|
3439
3443
|
* target function compared to beforehand.
|
|
3440
3444
|
*
|
|
3441
3445
|
* var myObj = {val: 1}
|
|
3442
|
-
*
|
|
3446
|
+
* , addTwo = function () { myObj.val += 2; };
|
|
3443
3447
|
*
|
|
3444
3448
|
* expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
|
|
3445
3449
|
* expect(addTwo).to.increase(myObj, 'val'); // Not recommended
|
|
@@ -3454,7 +3458,7 @@ Assertion.addMethod('changes', assertChanges);
|
|
|
3454
3458
|
* decreased by the expected amount.
|
|
3455
3459
|
*
|
|
3456
3460
|
* var myObj = {val: 1}
|
|
3457
|
-
*
|
|
3461
|
+
* , subtractTwo = function () { myObj.val -= 2; };
|
|
3458
3462
|
*
|
|
3459
3463
|
* expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
|
|
3460
3464
|
* expect(subtractTwo).to.not.increase(myObj, 'val'); // Not recommended
|
|
@@ -3463,7 +3467,7 @@ Assertion.addMethod('changes', assertChanges);
|
|
|
3463
3467
|
* exactly that.
|
|
3464
3468
|
*
|
|
3465
3469
|
* var myObj = {val: 1}
|
|
3466
|
-
*
|
|
3470
|
+
* , noop = function () {};
|
|
3467
3471
|
*
|
|
3468
3472
|
* expect(noop).to.not.change(myObj, 'val'); // Recommended
|
|
3469
3473
|
* expect(noop).to.not.increase(myObj, 'val'); // Not recommended
|
|
@@ -3474,13 +3478,13 @@ Assertion.addMethod('changes', assertChanges);
|
|
|
3474
3478
|
* use the second form.
|
|
3475
3479
|
*
|
|
3476
3480
|
* var myObj = {val: 1}
|
|
3477
|
-
*
|
|
3481
|
+
* , noop = function () {};
|
|
3478
3482
|
*
|
|
3479
3483
|
* expect(noop).to.increase(myObj, 'val', 'nooo why fail??');
|
|
3480
3484
|
*
|
|
3481
3485
|
* var val = 1
|
|
3482
|
-
*
|
|
3483
|
-
*
|
|
3486
|
+
* , noop = function () {}
|
|
3487
|
+
* , getVal = function () { return val; };
|
|
3484
3488
|
*
|
|
3485
3489
|
* expect(noop, 'nooo why fail??').to.increase(getVal);
|
|
3486
3490
|
*
|
|
@@ -3488,13 +3492,12 @@ Assertion.addMethod('changes', assertChanges);
|
|
|
3488
3492
|
*
|
|
3489
3493
|
* @name increase
|
|
3490
3494
|
* @alias increases
|
|
3491
|
-
* @param {
|
|
3492
|
-
* @param {
|
|
3493
|
-
* @param {
|
|
3495
|
+
* @param {string | Function} subject
|
|
3496
|
+
* @param {string} prop name _optional_
|
|
3497
|
+
* @param {string} msg _optional_
|
|
3494
3498
|
* @namespace BDD
|
|
3495
|
-
* @
|
|
3499
|
+
* @public
|
|
3496
3500
|
*/
|
|
3497
|
-
|
|
3498
3501
|
function assertIncreases (subject, prop, msg) {
|
|
3499
3502
|
if (msg) flag(this, 'message', msg);
|
|
3500
3503
|
var fn = flag(this, 'object')
|
|
@@ -3607,13 +3610,12 @@ Assertion.addMethod('increases', assertIncreases);
|
|
|
3607
3610
|
*
|
|
3608
3611
|
* @name decrease
|
|
3609
3612
|
* @alias decreases
|
|
3610
|
-
* @param {
|
|
3611
|
-
* @param {
|
|
3612
|
-
* @param {
|
|
3613
|
+
* @param {string | Function} subject
|
|
3614
|
+
* @param {string} prop name _optional_
|
|
3615
|
+
* @param {string} msg _optional_
|
|
3613
3616
|
* @namespace BDD
|
|
3614
|
-
* @
|
|
3617
|
+
* @public
|
|
3615
3618
|
*/
|
|
3616
|
-
|
|
3617
3619
|
function assertDecreases (subject, prop, msg) {
|
|
3618
3620
|
if (msg) flag(this, 'message', msg);
|
|
3619
3621
|
var fn = flag(this, 'object')
|
|
@@ -3714,12 +3716,11 @@ Assertion.addMethod('decreases', assertDecreases);
|
|
|
3714
3716
|
* expect(addTwo, 'nooo why fail??').to.increase(myObj, 'val').by(3);
|
|
3715
3717
|
*
|
|
3716
3718
|
* @name by
|
|
3717
|
-
* @param {
|
|
3718
|
-
* @param {
|
|
3719
|
+
* @param {number} delta
|
|
3720
|
+
* @param {string} msg _optional_
|
|
3719
3721
|
* @namespace BDD
|
|
3720
|
-
* @
|
|
3722
|
+
* @public
|
|
3721
3723
|
*/
|
|
3722
|
-
|
|
3723
3724
|
function assertDelta(delta, msg) {
|
|
3724
3725
|
if (msg) flag(this, 'message', msg);
|
|
3725
3726
|
|
|
@@ -3756,8 +3757,8 @@ Assertion.addMethod('by', assertDelta);
|
|
|
3756
3757
|
* Add `.not` earlier in the chain to negate `.extensible`.
|
|
3757
3758
|
*
|
|
3758
3759
|
* var nonExtensibleObject = Object.preventExtensions({})
|
|
3759
|
-
*
|
|
3760
|
-
*
|
|
3760
|
+
* , sealedObject = Object.seal({})
|
|
3761
|
+
* , frozenObject = Object.freeze({});
|
|
3761
3762
|
*
|
|
3762
3763
|
* expect(nonExtensibleObject).to.not.be.extensible;
|
|
3763
3764
|
* expect(sealedObject).to.not.be.extensible;
|
|
@@ -3770,9 +3771,8 @@ Assertion.addMethod('by', assertDelta);
|
|
|
3770
3771
|
*
|
|
3771
3772
|
* @name extensible
|
|
3772
3773
|
* @namespace BDD
|
|
3773
|
-
* @
|
|
3774
|
+
* @public
|
|
3774
3775
|
*/
|
|
3775
|
-
|
|
3776
3776
|
Assertion.addProperty('extensible', function() {
|
|
3777
3777
|
var obj = flag(this, 'object');
|
|
3778
3778
|
|
|
@@ -3815,9 +3815,8 @@ Assertion.addProperty('extensible', function() {
|
|
|
3815
3815
|
*
|
|
3816
3816
|
* @name sealed
|
|
3817
3817
|
* @namespace BDD
|
|
3818
|
-
* @
|
|
3818
|
+
* @public
|
|
3819
3819
|
*/
|
|
3820
|
-
|
|
3821
3820
|
Assertion.addProperty('sealed', function() {
|
|
3822
3821
|
var obj = flag(this, 'object');
|
|
3823
3822
|
|
|
@@ -3857,9 +3856,8 @@ Assertion.addProperty('sealed', function() {
|
|
|
3857
3856
|
*
|
|
3858
3857
|
* @name frozen
|
|
3859
3858
|
* @namespace BDD
|
|
3860
|
-
* @
|
|
3859
|
+
* @public
|
|
3861
3860
|
*/
|
|
3862
|
-
|
|
3863
3861
|
Assertion.addProperty('frozen', function() {
|
|
3864
3862
|
var obj = flag(this, 'object');
|
|
3865
3863
|
|
|
@@ -3923,9 +3921,8 @@ Assertion.addProperty('frozen', function() {
|
|
|
3923
3921
|
*
|
|
3924
3922
|
* @name finite
|
|
3925
3923
|
* @namespace BDD
|
|
3926
|
-
* @
|
|
3924
|
+
* @public
|
|
3927
3925
|
*/
|
|
3928
|
-
|
|
3929
3926
|
Assertion.addProperty('finite', function(msg) {
|
|
3930
3927
|
var obj = flag(this, 'object');
|
|
3931
3928
|
|