tutuca 0.9.112 → 0.9.114
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/dist/chai.js +1180 -359
- package/dist/tutuca-cli.js +13175 -12112
- package/dist/tutuca-components.js +323 -354
- package/dist/tutuca-dev.ext.js +1955 -2033
- package/dist/tutuca-dev.js +3254 -2627
- package/dist/tutuca-dev.min.js +5 -5
- package/dist/tutuca-extra.ext.js +1044 -1222
- package/dist/tutuca-extra.js +1261 -1480
- package/dist/tutuca-extra.min.js +3 -3
- package/dist/tutuca-storybook.js +270 -120
- package/dist/tutuca.ext.js +1026 -1213
- package/dist/tutuca.js +1243 -1471
- package/dist/tutuca.min.js +3 -3
- package/package.json +24 -21
- package/skill/tutuca/cli.md +1 -1
- package/skill/tutuca/margaui.md +39 -0
- package/skill/tutuca/storybook.md +26 -0
- package/skill/tutuca/testing.md +5 -4
- package/skill/tutuca-source/tutuca.ext.js +1026 -1213
package/dist/chai.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// node_modules/chai/index.js
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defNormalProp = (obj, key, value) =>
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
5
|
var __export = (target, all) => {
|
|
6
6
|
for (var name in all)
|
|
@@ -160,7 +160,7 @@ var _AssertionError = class _AssertionError2 extends Error {
|
|
|
160
160
|
name: this.name,
|
|
161
161
|
message: this.message,
|
|
162
162
|
ok: false,
|
|
163
|
-
stack: stack !== false ? this.stack :
|
|
163
|
+
stack: stack !== false ? this.stack : void 0
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
};
|
|
@@ -184,7 +184,11 @@ function expectTypes(obj, types) {
|
|
|
184
184
|
if (!types.some(function(expected) {
|
|
185
185
|
return objType === expected;
|
|
186
186
|
})) {
|
|
187
|
-
throw new AssertionError(
|
|
187
|
+
throw new AssertionError(
|
|
188
|
+
flagMsg + "object tested must be " + str + ", but " + objType + " given",
|
|
189
|
+
void 0,
|
|
190
|
+
ssfi
|
|
191
|
+
);
|
|
188
192
|
}
|
|
189
193
|
}
|
|
190
194
|
__name(expectTypes, "expectTypes");
|
|
@@ -197,9 +201,12 @@ var ansiColors = {
|
|
|
197
201
|
dim: ["2", "22"],
|
|
198
202
|
italic: ["3", "23"],
|
|
199
203
|
underline: ["4", "24"],
|
|
204
|
+
// 5 & 6 are blinking
|
|
200
205
|
inverse: ["7", "27"],
|
|
201
206
|
hidden: ["8", "28"],
|
|
202
207
|
strike: ["9", "29"],
|
|
208
|
+
// 10-20 are fonts
|
|
209
|
+
// 21-29 are resets for 1-9
|
|
203
210
|
black: ["30", "39"],
|
|
204
211
|
red: ["31", "39"],
|
|
205
212
|
green: ["32", "39"],
|
|
@@ -248,6 +255,7 @@ function normaliseOptions({
|
|
|
248
255
|
maxArrayLength = Infinity,
|
|
249
256
|
breakLength = Infinity,
|
|
250
257
|
seen = [],
|
|
258
|
+
// eslint-disable-next-line no-shadow
|
|
251
259
|
truncate: truncate2 = Infinity,
|
|
252
260
|
stylize = String
|
|
253
261
|
} = {}, inspect3) {
|
|
@@ -300,7 +308,7 @@ function inspectList(list, options, inspectItem, separator = ", ") {
|
|
|
300
308
|
let output = "";
|
|
301
309
|
let peek = "";
|
|
302
310
|
let truncated = "";
|
|
303
|
-
for (let i = 0;i < size; i += 1) {
|
|
311
|
+
for (let i = 0; i < size; i += 1) {
|
|
304
312
|
const last = i + 1 === list.length;
|
|
305
313
|
const secondToLast = i + 2 === list.length;
|
|
306
314
|
truncated = `${truncator}(${list.length - i})`;
|
|
@@ -378,7 +386,7 @@ function inspectTypedArray(array, options) {
|
|
|
378
386
|
if (!array.length && !nonIndexProperties.length)
|
|
379
387
|
return `${name}[]`;
|
|
380
388
|
let output = "";
|
|
381
|
-
for (let i = 0;i < array.length; i++) {
|
|
389
|
+
for (let i = 0; i < array.length; i++) {
|
|
382
390
|
const string = `${options.stylize(truncate(array[i], options.truncate), "number")}${i === array.length - 1 ? "" : ", "}`;
|
|
383
391
|
options.truncate -= string.length;
|
|
384
392
|
if (array[i] !== array.length && options.truncate <= 3) {
|
|
@@ -485,7 +493,7 @@ __name(inspectSet, "inspectSet");
|
|
|
485
493
|
var stringEscapeChars = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", "g");
|
|
486
494
|
var escapeCharacters = {
|
|
487
495
|
"\b": "\\b",
|
|
488
|
-
"
|
|
496
|
+
" ": "\\t",
|
|
489
497
|
"\n": "\\n",
|
|
490
498
|
"\f": "\\f",
|
|
491
499
|
"\r": "\\r",
|
|
@@ -600,8 +608,7 @@ function inspectAttribute([key, value], options) {
|
|
|
600
608
|
}
|
|
601
609
|
__name(inspectAttribute, "inspectAttribute");
|
|
602
610
|
function inspectNodeCollection(collection, options) {
|
|
603
|
-
return inspectList(collection, options, inspectNode,
|
|
604
|
-
`);
|
|
611
|
+
return inspectList(collection, options, inspectNode, "\n");
|
|
605
612
|
}
|
|
606
613
|
__name(inspectNodeCollection, "inspectNodeCollection");
|
|
607
614
|
function inspectNode(node, options) {
|
|
@@ -639,7 +646,7 @@ __name(inspectHTML, "inspectHTML");
|
|
|
639
646
|
var symbolsSupported = typeof Symbol === "function" && typeof Symbol.for === "function";
|
|
640
647
|
var chaiInspect = symbolsSupported ? /* @__PURE__ */ Symbol.for("chai/inspect") : "@@chai/inspect";
|
|
641
648
|
var nodeInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
642
|
-
var constructorMap = /* @__PURE__ */ new WeakMap;
|
|
649
|
+
var constructorMap = /* @__PURE__ */ new WeakMap();
|
|
643
650
|
var stringTagMap = {};
|
|
644
651
|
var baseTypesMap = {
|
|
645
652
|
undefined: /* @__PURE__ */ __name((value, options) => options.stylize("undefined", "undefined"), "undefined"),
|
|
@@ -655,6 +662,7 @@ var baseTypesMap = {
|
|
|
655
662
|
function: inspectFunction,
|
|
656
663
|
Function: inspectFunction,
|
|
657
664
|
symbol: inspectSymbol,
|
|
665
|
+
// A Symbol polyfill will return `Symbol` not `symbol` from typedetect
|
|
658
666
|
Symbol: inspectSymbol,
|
|
659
667
|
Array: inspectArray,
|
|
660
668
|
Date: inspectDate,
|
|
@@ -662,6 +670,7 @@ var baseTypesMap = {
|
|
|
662
670
|
Set: inspectSet,
|
|
663
671
|
RegExp: inspectRegExp,
|
|
664
672
|
Promise: promise_default,
|
|
673
|
+
// WeakSet, WeakMap are totally opaque to us
|
|
665
674
|
WeakSet: /* @__PURE__ */ __name((value, options) => options.stylize("WeakSet{…}", "special"), "WeakSet"),
|
|
666
675
|
WeakMap: /* @__PURE__ */ __name((value, options) => options.stylize("WeakMap{…}", "special"), "WeakMap"),
|
|
667
676
|
Arguments: inspectArguments,
|
|
@@ -738,11 +747,110 @@ function inspect(value, opts = {}) {
|
|
|
738
747
|
}
|
|
739
748
|
__name(inspect, "inspect");
|
|
740
749
|
var config = {
|
|
750
|
+
/**
|
|
751
|
+
* ### config.includeStack
|
|
752
|
+
*
|
|
753
|
+
* User configurable property, influences whether stack trace
|
|
754
|
+
* is included in Assertion error message. Default of false
|
|
755
|
+
* suppresses stack trace in the error message.
|
|
756
|
+
*
|
|
757
|
+
* chai.config.includeStack = true; // enable stack on error
|
|
758
|
+
*
|
|
759
|
+
* @param {boolean}
|
|
760
|
+
* @public
|
|
761
|
+
*/
|
|
741
762
|
includeStack: false,
|
|
763
|
+
/**
|
|
764
|
+
* ### config.showDiff
|
|
765
|
+
*
|
|
766
|
+
* User configurable property, influences whether or not
|
|
767
|
+
* the `showDiff` flag should be included in the thrown
|
|
768
|
+
* AssertionErrors. `false` will always be `false`; `true`
|
|
769
|
+
* will be true when the assertion has requested a diff
|
|
770
|
+
* be shown.
|
|
771
|
+
*
|
|
772
|
+
* @param {boolean}
|
|
773
|
+
* @public
|
|
774
|
+
*/
|
|
742
775
|
showDiff: true,
|
|
776
|
+
/**
|
|
777
|
+
* ### config.truncateThreshold
|
|
778
|
+
*
|
|
779
|
+
* User configurable property, sets length threshold for actual and
|
|
780
|
+
* expected values in assertion errors. If this threshold is exceeded, for
|
|
781
|
+
* example for large data structures, the value is replaced with something
|
|
782
|
+
* like `[ Array(3) ]` or `{ Object (prop1, prop2) }`.
|
|
783
|
+
*
|
|
784
|
+
* Set it to zero if you want to disable truncating altogether.
|
|
785
|
+
*
|
|
786
|
+
* This is especially userful when doing assertions on arrays: having this
|
|
787
|
+
* set to a reasonable large value makes the failure messages readily
|
|
788
|
+
* inspectable.
|
|
789
|
+
*
|
|
790
|
+
* chai.config.truncateThreshold = 0; // disable truncating
|
|
791
|
+
*
|
|
792
|
+
* @param {number}
|
|
793
|
+
* @public
|
|
794
|
+
*/
|
|
743
795
|
truncateThreshold: 40,
|
|
796
|
+
/**
|
|
797
|
+
* ### config.useProxy
|
|
798
|
+
*
|
|
799
|
+
* User configurable property, defines if chai will use a Proxy to throw
|
|
800
|
+
* an error when a non-existent property is read, which protects users
|
|
801
|
+
* from typos when using property-based assertions.
|
|
802
|
+
*
|
|
803
|
+
* Set it to false if you want to disable this feature.
|
|
804
|
+
*
|
|
805
|
+
* chai.config.useProxy = false; // disable use of Proxy
|
|
806
|
+
*
|
|
807
|
+
* This feature is automatically disabled regardless of this config value
|
|
808
|
+
* in environments that don't support proxies.
|
|
809
|
+
*
|
|
810
|
+
* @param {boolean}
|
|
811
|
+
* @public
|
|
812
|
+
*/
|
|
744
813
|
useProxy: true,
|
|
814
|
+
/**
|
|
815
|
+
* ### config.proxyExcludedKeys
|
|
816
|
+
*
|
|
817
|
+
* User configurable property, defines which properties should be ignored
|
|
818
|
+
* instead of throwing an error if they do not exist on the assertion.
|
|
819
|
+
* This is only applied if the environment Chai is running in supports proxies and
|
|
820
|
+
* if the `useProxy` configuration setting is enabled.
|
|
821
|
+
* By default, `then` and `inspect` will not throw an error if they do not exist on the
|
|
822
|
+
* assertion object because the `.inspect` property is read by `util.inspect` (for example, when
|
|
823
|
+
* using `console.log` on the assertion object) and `.then` is necessary for promise type-checking.
|
|
824
|
+
*
|
|
825
|
+
* // By default these keys will not throw an error if they do not exist on the assertion object
|
|
826
|
+
* chai.config.proxyExcludedKeys = ['then', 'inspect'];
|
|
827
|
+
*
|
|
828
|
+
* @param {Array}
|
|
829
|
+
* @public
|
|
830
|
+
*/
|
|
745
831
|
proxyExcludedKeys: ["then", "catch", "inspect", "toJSON"],
|
|
832
|
+
/**
|
|
833
|
+
* ### config.deepEqual
|
|
834
|
+
*
|
|
835
|
+
* User configurable property, defines which a custom function to use for deepEqual
|
|
836
|
+
* comparisons.
|
|
837
|
+
* By default, the function used is the one from the `deep-eql` package without custom comparator.
|
|
838
|
+
*
|
|
839
|
+
* // use a custom comparator
|
|
840
|
+
* chai.config.deepEqual = (expected, actual) => {
|
|
841
|
+
* return chai.util.eql(expected, actual, {
|
|
842
|
+
* comparator: (expected, actual) => {
|
|
843
|
+
* // for non number comparison, use the default behavior
|
|
844
|
+
* if(typeof expected !== 'number') return null;
|
|
845
|
+
* // allow a difference of 10 between compared numbers
|
|
846
|
+
* return typeof actual === 'number' && Math.abs(actual - expected) < 10
|
|
847
|
+
* }
|
|
848
|
+
* })
|
|
849
|
+
* };
|
|
850
|
+
*
|
|
851
|
+
* @param {Function}
|
|
852
|
+
* @public
|
|
853
|
+
*/
|
|
746
854
|
deepEqual: null
|
|
747
855
|
};
|
|
748
856
|
function inspect2(obj, showHidden, depth, colors) {
|
|
@@ -780,8 +888,7 @@ function getMessage2(obj, args) {
|
|
|
780
888
|
let actual = getActual(obj, args);
|
|
781
889
|
let msg = negate ? args[2] : args[1];
|
|
782
890
|
let flagMsg = flag(obj, "message");
|
|
783
|
-
if (typeof msg === "function")
|
|
784
|
-
msg = msg();
|
|
891
|
+
if (typeof msg === "function") msg = msg();
|
|
785
892
|
msg = msg || "";
|
|
786
893
|
msg = msg.replace(/#\{this\}/g, function() {
|
|
787
894
|
return objDisplay(val);
|
|
@@ -862,7 +969,7 @@ function memoizeSet(leftHandOperand, rightHandOperand, memoizeMap, result) {
|
|
|
862
969
|
if (leftHandMap) {
|
|
863
970
|
leftHandMap.set(rightHandOperand, result);
|
|
864
971
|
} else {
|
|
865
|
-
leftHandMap = new MemoizeMap;
|
|
972
|
+
leftHandMap = new MemoizeMap();
|
|
866
973
|
leftHandMap.set(rightHandOperand, result);
|
|
867
974
|
memoizeMap.set(leftHandOperand, leftHandMap);
|
|
868
975
|
}
|
|
@@ -884,7 +991,8 @@ function simpleEqual(leftHandOperand, rightHandOperand) {
|
|
|
884
991
|
if (leftHandOperand === rightHandOperand) {
|
|
885
992
|
return leftHandOperand !== 0 || 1 / leftHandOperand === 1 / rightHandOperand;
|
|
886
993
|
}
|
|
887
|
-
if (leftHandOperand !== leftHandOperand &&
|
|
994
|
+
if (leftHandOperand !== leftHandOperand && // eslint-disable-line no-self-compare
|
|
995
|
+
rightHandOperand !== rightHandOperand) {
|
|
888
996
|
return true;
|
|
889
997
|
}
|
|
890
998
|
if (isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
|
|
@@ -895,7 +1003,7 @@ function simpleEqual(leftHandOperand, rightHandOperand) {
|
|
|
895
1003
|
__name(simpleEqual, "simpleEqual");
|
|
896
1004
|
function extensiveDeepEqual(leftHandOperand, rightHandOperand, options) {
|
|
897
1005
|
options = options || {};
|
|
898
|
-
options.memoize = options.memoize === false ? false : options.memoize || new MemoizeMap;
|
|
1006
|
+
options.memoize = options.memoize === false ? false : options.memoize || new MemoizeMap();
|
|
899
1007
|
var comparator = options && options.comparator;
|
|
900
1008
|
var memoizeResultLeft = memoizeCompare(leftHandOperand, rightHandOperand, options.memoize);
|
|
901
1009
|
if (memoizeResultLeft !== null) {
|
|
@@ -1067,7 +1175,7 @@ __name(getEnumerableKeys, "getEnumerableKeys");
|
|
|
1067
1175
|
function getEnumerableSymbols(target) {
|
|
1068
1176
|
var keys = [];
|
|
1069
1177
|
var allKeys = Object.getOwnPropertySymbols(target);
|
|
1070
|
-
for (var i = 0;i < allKeys.length; i += 1) {
|
|
1178
|
+
for (var i = 0; i < allKeys.length; i += 1) {
|
|
1071
1179
|
var key = allKeys[i];
|
|
1072
1180
|
if (Object.getOwnPropertyDescriptor(target, key).enumerable) {
|
|
1073
1181
|
keys.push(key);
|
|
@@ -1081,7 +1189,7 @@ function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
|
|
|
1081
1189
|
if (length === 0) {
|
|
1082
1190
|
return true;
|
|
1083
1191
|
}
|
|
1084
|
-
for (var i = 0;i < length; i += 1) {
|
|
1192
|
+
for (var i = 0; i < length; i += 1) {
|
|
1085
1193
|
if (deepEqual(leftHandOperand[keys[i]], rightHandOperand[keys[i]], options) === false) {
|
|
1086
1194
|
return false;
|
|
1087
1195
|
}
|
|
@@ -1158,7 +1266,7 @@ function internalGetPathValue(obj, parsed, pathDepth) {
|
|
|
1158
1266
|
let temporaryValue = obj;
|
|
1159
1267
|
let res = null;
|
|
1160
1268
|
pathDepth = typeof pathDepth === "undefined" ? parsed.length : pathDepth;
|
|
1161
|
-
for (let i = 0;i < pathDepth; i++) {
|
|
1269
|
+
for (let i = 0; i < pathDepth; i++) {
|
|
1162
1270
|
const part = parsed[i];
|
|
1163
1271
|
if (temporaryValue) {
|
|
1164
1272
|
if (typeof part.p === "undefined") {
|
|
@@ -1187,6 +1295,41 @@ function getPathInfo(obj, path) {
|
|
|
1187
1295
|
}
|
|
1188
1296
|
__name(getPathInfo, "getPathInfo");
|
|
1189
1297
|
var _Assertion = class _Assertion2 {
|
|
1298
|
+
/**
|
|
1299
|
+
* Creates object for chaining.
|
|
1300
|
+
* `Assertion` objects contain metadata in the form of flags. Three flags can
|
|
1301
|
+
* be assigned during instantiation by passing arguments to this constructor:
|
|
1302
|
+
*
|
|
1303
|
+
* - `object`: This flag contains the target of the assertion. For example, in
|
|
1304
|
+
* the assertion `expect(numKittens).to.equal(7);`, the `object` flag will
|
|
1305
|
+
* contain `numKittens` so that the `equal` assertion can reference it when
|
|
1306
|
+
* needed.
|
|
1307
|
+
*
|
|
1308
|
+
* - `message`: This flag contains an optional custom error message to be
|
|
1309
|
+
* prepended to the error message that's generated by the assertion when it
|
|
1310
|
+
* fails.
|
|
1311
|
+
*
|
|
1312
|
+
* - `ssfi`: This flag stands for "start stack function indicator". It
|
|
1313
|
+
* contains a function reference that serves as the starting point for
|
|
1314
|
+
* removing frames from the stack trace of the error that's created by the
|
|
1315
|
+
* assertion when it fails. The goal is to provide a cleaner stack trace to
|
|
1316
|
+
* end users by removing Chai's internal functions. Note that it only works
|
|
1317
|
+
* in environments that support `Error.captureStackTrace`, and only when
|
|
1318
|
+
* `Chai.config.includeStack` hasn't been set to `false`.
|
|
1319
|
+
*
|
|
1320
|
+
* - `lockSsfi`: This flag controls whether or not the given `ssfi` flag
|
|
1321
|
+
* should retain its current value, even as assertions are chained off of
|
|
1322
|
+
* this object. This is usually set to `true` when creating a new assertion
|
|
1323
|
+
* from within another assertion. It's also temporarily set to `true` before
|
|
1324
|
+
* an overwritten assertion gets called by the overwriting assertion.
|
|
1325
|
+
*
|
|
1326
|
+
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
|
|
1327
|
+
*
|
|
1328
|
+
* @param {unknown} obj target of the assertion
|
|
1329
|
+
* @param {string} [msg] (optional) custom error message
|
|
1330
|
+
* @param {Function} [ssfi] (optional) starting point for removing stack frames
|
|
1331
|
+
* @param {boolean} [lockSsfi] (optional) whether or not the ssfi flag is locked
|
|
1332
|
+
*/
|
|
1190
1333
|
constructor(obj, msg, ssfi, lockSsfi) {
|
|
1191
1334
|
__publicField(this, "__flags", {});
|
|
1192
1335
|
flag(this, "ssfi", ssfi || _Assertion2);
|
|
@@ -1196,48 +1339,97 @@ var _Assertion = class _Assertion2 {
|
|
|
1196
1339
|
flag(this, "eql", config.deepEqual || deep_eql_default);
|
|
1197
1340
|
return proxify(this);
|
|
1198
1341
|
}
|
|
1342
|
+
/** @returns {boolean} */
|
|
1199
1343
|
static get includeStack() {
|
|
1200
|
-
console.warn(
|
|
1344
|
+
console.warn(
|
|
1345
|
+
"Assertion.includeStack is deprecated, use chai.config.includeStack instead."
|
|
1346
|
+
);
|
|
1201
1347
|
return config.includeStack;
|
|
1202
1348
|
}
|
|
1349
|
+
/** @param {boolean} value */
|
|
1203
1350
|
static set includeStack(value) {
|
|
1204
|
-
console.warn(
|
|
1351
|
+
console.warn(
|
|
1352
|
+
"Assertion.includeStack is deprecated, use chai.config.includeStack instead."
|
|
1353
|
+
);
|
|
1205
1354
|
config.includeStack = value;
|
|
1206
1355
|
}
|
|
1356
|
+
/** @returns {boolean} */
|
|
1207
1357
|
static get showDiff() {
|
|
1208
|
-
console.warn(
|
|
1358
|
+
console.warn(
|
|
1359
|
+
"Assertion.showDiff is deprecated, use chai.config.showDiff instead."
|
|
1360
|
+
);
|
|
1209
1361
|
return config.showDiff;
|
|
1210
1362
|
}
|
|
1363
|
+
/** @param {boolean} value */
|
|
1211
1364
|
static set showDiff(value) {
|
|
1212
|
-
console.warn(
|
|
1365
|
+
console.warn(
|
|
1366
|
+
"Assertion.showDiff is deprecated, use chai.config.showDiff instead."
|
|
1367
|
+
);
|
|
1213
1368
|
config.showDiff = value;
|
|
1214
1369
|
}
|
|
1370
|
+
/**
|
|
1371
|
+
* @param {string} name
|
|
1372
|
+
* @param {Function} fn
|
|
1373
|
+
*/
|
|
1215
1374
|
static addProperty(name, fn) {
|
|
1216
1375
|
addProperty(this.prototype, name, fn);
|
|
1217
1376
|
}
|
|
1377
|
+
/**
|
|
1378
|
+
* @param {string} name
|
|
1379
|
+
* @param {Function} fn
|
|
1380
|
+
*/
|
|
1218
1381
|
static addMethod(name, fn) {
|
|
1219
1382
|
addMethod(this.prototype, name, fn);
|
|
1220
1383
|
}
|
|
1384
|
+
/**
|
|
1385
|
+
* @param {string} name
|
|
1386
|
+
* @param {Function} fn
|
|
1387
|
+
* @param {Function} chainingBehavior
|
|
1388
|
+
*/
|
|
1221
1389
|
static addChainableMethod(name, fn, chainingBehavior) {
|
|
1222
1390
|
addChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
1223
1391
|
}
|
|
1392
|
+
/**
|
|
1393
|
+
* @param {string} name
|
|
1394
|
+
* @param {Function} fn
|
|
1395
|
+
*/
|
|
1224
1396
|
static overwriteProperty(name, fn) {
|
|
1225
1397
|
overwriteProperty(this.prototype, name, fn);
|
|
1226
1398
|
}
|
|
1399
|
+
/**
|
|
1400
|
+
* @param {string} name
|
|
1401
|
+
* @param {Function} fn
|
|
1402
|
+
*/
|
|
1227
1403
|
static overwriteMethod(name, fn) {
|
|
1228
1404
|
overwriteMethod(this.prototype, name, fn);
|
|
1229
1405
|
}
|
|
1406
|
+
/**
|
|
1407
|
+
* @param {string} name
|
|
1408
|
+
* @param {Function} fn
|
|
1409
|
+
* @param {Function} chainingBehavior
|
|
1410
|
+
*/
|
|
1230
1411
|
static overwriteChainableMethod(name, fn, chainingBehavior) {
|
|
1231
1412
|
overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
1232
1413
|
}
|
|
1414
|
+
/**
|
|
1415
|
+
* ### .assert(expression, message, negateMessage, expected, actual, showDiff)
|
|
1416
|
+
*
|
|
1417
|
+
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
|
|
1418
|
+
*
|
|
1419
|
+
* @name assert
|
|
1420
|
+
* @param {unknown} _expr to be tested
|
|
1421
|
+
* @param {string | Function} msg or function that returns message to display if expression fails
|
|
1422
|
+
* @param {string | Function} _negateMsg or function that returns negatedMessage to display if negated expression fails
|
|
1423
|
+
* @param {unknown} expected value (remember to check for negation)
|
|
1424
|
+
* @param {unknown} _actual (optional) will default to `this.obj`
|
|
1425
|
+
* @param {boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
|
|
1426
|
+
* @returns {void}
|
|
1427
|
+
*/
|
|
1233
1428
|
assert(_expr, msg, _negateMsg, expected, _actual, showDiff) {
|
|
1234
1429
|
const ok = test(this, arguments);
|
|
1235
|
-
if (
|
|
1236
|
-
|
|
1237
|
-
if (
|
|
1238
|
-
showDiff = false;
|
|
1239
|
-
if (config.showDiff !== true)
|
|
1240
|
-
showDiff = false;
|
|
1430
|
+
if (false !== showDiff) showDiff = true;
|
|
1431
|
+
if (void 0 === expected && void 0 === _actual) showDiff = false;
|
|
1432
|
+
if (true !== config.showDiff) showDiff = false;
|
|
1241
1433
|
if (!ok) {
|
|
1242
1434
|
msg = getMessage2(this, arguments);
|
|
1243
1435
|
const actual = getActual(this, arguments);
|
|
@@ -1250,19 +1442,34 @@ var _Assertion = class _Assertion2 {
|
|
|
1250
1442
|
if (operator) {
|
|
1251
1443
|
assertionErrorObjectProperties.operator = operator;
|
|
1252
1444
|
}
|
|
1253
|
-
throw new AssertionError(
|
|
1445
|
+
throw new AssertionError(
|
|
1446
|
+
msg,
|
|
1447
|
+
assertionErrorObjectProperties,
|
|
1448
|
+
// @ts-expect-error Not sure what to do about these types yet
|
|
1449
|
+
config.includeStack ? this.assert : flag(this, "ssfi")
|
|
1450
|
+
);
|
|
1254
1451
|
}
|
|
1255
1452
|
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Quick reference to stored `actual` value for plugin developers.
|
|
1455
|
+
*
|
|
1456
|
+
* @returns {unknown}
|
|
1457
|
+
*/
|
|
1256
1458
|
get _obj() {
|
|
1257
1459
|
return flag(this, "object");
|
|
1258
1460
|
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Quick reference to stored `actual` value for plugin developers.
|
|
1463
|
+
*
|
|
1464
|
+
* @param {unknown} val
|
|
1465
|
+
*/
|
|
1259
1466
|
set _obj(val) {
|
|
1260
1467
|
flag(this, "object", val);
|
|
1261
1468
|
}
|
|
1262
1469
|
};
|
|
1263
1470
|
__name(_Assertion, "Assertion");
|
|
1264
1471
|
var Assertion = _Assertion;
|
|
1265
|
-
var events = new EventTarget;
|
|
1472
|
+
var events = new EventTarget();
|
|
1266
1473
|
var _PluginEvent = class _PluginEvent2 extends Event {
|
|
1267
1474
|
constructor(type3, name, fn) {
|
|
1268
1475
|
super(type3);
|
|
@@ -1277,16 +1484,16 @@ function isProxyEnabled() {
|
|
|
1277
1484
|
}
|
|
1278
1485
|
__name(isProxyEnabled, "isProxyEnabled");
|
|
1279
1486
|
function addProperty(ctx, name, getter) {
|
|
1280
|
-
getter = getter ===
|
|
1487
|
+
getter = getter === void 0 ? function() {
|
|
1488
|
+
} : getter;
|
|
1281
1489
|
Object.defineProperty(ctx, name, {
|
|
1282
1490
|
get: /* @__PURE__ */ __name(function propertyGetter() {
|
|
1283
1491
|
if (!isProxyEnabled() && !flag(this, "lockSsfi")) {
|
|
1284
1492
|
flag(this, "ssfi", propertyGetter);
|
|
1285
1493
|
}
|
|
1286
1494
|
let result = getter.call(this);
|
|
1287
|
-
if (result !==
|
|
1288
|
-
|
|
1289
|
-
let newAssertion = new Assertion;
|
|
1495
|
+
if (result !== void 0) return result;
|
|
1496
|
+
let newAssertion = new Assertion();
|
|
1290
1497
|
transferFlags(this, newAssertion);
|
|
1291
1498
|
return newAssertion;
|
|
1292
1499
|
}, "propertyGetter"),
|
|
@@ -1295,16 +1502,20 @@ function addProperty(ctx, name, getter) {
|
|
|
1295
1502
|
events.dispatchEvent(new PluginEvent("addProperty", name, getter));
|
|
1296
1503
|
}
|
|
1297
1504
|
__name(addProperty, "addProperty");
|
|
1298
|
-
var fnLengthDesc = Object.getOwnPropertyDescriptor(function() {
|
|
1505
|
+
var fnLengthDesc = Object.getOwnPropertyDescriptor(function() {
|
|
1506
|
+
}, "length");
|
|
1299
1507
|
function addLengthGuard(fn, assertionName, isChainable) {
|
|
1300
|
-
if (!fnLengthDesc.configurable)
|
|
1301
|
-
return fn;
|
|
1508
|
+
if (!fnLengthDesc.configurable) return fn;
|
|
1302
1509
|
Object.defineProperty(fn, "length", {
|
|
1303
1510
|
get: /* @__PURE__ */ __name(function() {
|
|
1304
1511
|
if (isChainable) {
|
|
1305
|
-
throw Error(
|
|
1512
|
+
throw Error(
|
|
1513
|
+
"Invalid Chai property: " + assertionName + '.length. Due to a compatibility issue, "length" cannot directly follow "' + assertionName + '". Use "' + assertionName + '.lengthOf" instead.'
|
|
1514
|
+
);
|
|
1306
1515
|
}
|
|
1307
|
-
throw Error(
|
|
1516
|
+
throw Error(
|
|
1517
|
+
"Invalid Chai property: " + assertionName + '.length. See docs for proper usage of "' + assertionName + '".'
|
|
1518
|
+
);
|
|
1308
1519
|
}, "get")
|
|
1309
1520
|
});
|
|
1310
1521
|
return fn;
|
|
@@ -1328,18 +1539,23 @@ function getProperties(object) {
|
|
|
1328
1539
|
__name(getProperties, "getProperties");
|
|
1329
1540
|
var builtins = ["__flags", "__methods", "_obj", "assert"];
|
|
1330
1541
|
function proxify(obj, nonChainableMethodName) {
|
|
1331
|
-
if (!isProxyEnabled())
|
|
1332
|
-
return obj;
|
|
1542
|
+
if (!isProxyEnabled()) return obj;
|
|
1333
1543
|
return new Proxy(obj, {
|
|
1334
1544
|
get: /* @__PURE__ */ __name(function proxyGetter(target, property) {
|
|
1335
1545
|
if (typeof property === "string" && config.proxyExcludedKeys.indexOf(property) === -1 && !Reflect.has(target, property)) {
|
|
1336
1546
|
if (nonChainableMethodName) {
|
|
1337
|
-
throw Error(
|
|
1547
|
+
throw Error(
|
|
1548
|
+
"Invalid Chai property: " + nonChainableMethodName + "." + property + '. See docs for proper usage of "' + nonChainableMethodName + '".'
|
|
1549
|
+
);
|
|
1338
1550
|
}
|
|
1339
1551
|
let suggestion = null;
|
|
1340
1552
|
let suggestionDistance = 4;
|
|
1341
1553
|
getProperties(target).forEach(function(prop) {
|
|
1342
|
-
if (
|
|
1554
|
+
if (
|
|
1555
|
+
// we actually mean to check `Object.prototype` here
|
|
1556
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
1557
|
+
!Object.prototype.hasOwnProperty(prop) && builtins.indexOf(prop) === -1
|
|
1558
|
+
) {
|
|
1343
1559
|
let dist = stringDistanceCapped(property, prop, suggestionDistance);
|
|
1344
1560
|
if (dist < suggestionDistance) {
|
|
1345
1561
|
suggestion = prop;
|
|
@@ -1348,7 +1564,9 @@ function proxify(obj, nonChainableMethodName) {
|
|
|
1348
1564
|
}
|
|
1349
1565
|
});
|
|
1350
1566
|
if (suggestion !== null) {
|
|
1351
|
-
throw Error(
|
|
1567
|
+
throw Error(
|
|
1568
|
+
"Invalid Chai property: " + property + '. Did you mean "' + suggestion + '"?'
|
|
1569
|
+
);
|
|
1352
1570
|
} else {
|
|
1353
1571
|
throw Error("Invalid Chai property: " + property);
|
|
1354
1572
|
}
|
|
@@ -1366,21 +1584,25 @@ function stringDistanceCapped(strA, strB, cap) {
|
|
|
1366
1584
|
return cap;
|
|
1367
1585
|
}
|
|
1368
1586
|
let memo = [];
|
|
1369
|
-
for (let i = 0;i <= strA.length; i++) {
|
|
1587
|
+
for (let i = 0; i <= strA.length; i++) {
|
|
1370
1588
|
memo[i] = Array(strB.length + 1).fill(0);
|
|
1371
1589
|
memo[i][0] = i;
|
|
1372
1590
|
}
|
|
1373
|
-
for (let j = 0;j < strB.length; j++) {
|
|
1591
|
+
for (let j = 0; j < strB.length; j++) {
|
|
1374
1592
|
memo[0][j] = j;
|
|
1375
1593
|
}
|
|
1376
|
-
for (let i = 1;i <= strA.length; i++) {
|
|
1594
|
+
for (let i = 1; i <= strA.length; i++) {
|
|
1377
1595
|
let ch = strA.charCodeAt(i - 1);
|
|
1378
|
-
for (let j = 1;j <= strB.length; j++) {
|
|
1596
|
+
for (let j = 1; j <= strB.length; j++) {
|
|
1379
1597
|
if (Math.abs(i - j) >= cap) {
|
|
1380
1598
|
memo[i][j] = cap;
|
|
1381
1599
|
continue;
|
|
1382
1600
|
}
|
|
1383
|
-
memo[i][j] = Math.min(
|
|
1601
|
+
memo[i][j] = Math.min(
|
|
1602
|
+
memo[i - 1][j] + 1,
|
|
1603
|
+
memo[i][j - 1] + 1,
|
|
1604
|
+
memo[i - 1][j - 1] + (ch === strB.charCodeAt(j - 1) ? 0 : 1)
|
|
1605
|
+
);
|
|
1384
1606
|
}
|
|
1385
1607
|
}
|
|
1386
1608
|
return memo[strA.length][strB.length];
|
|
@@ -1392,9 +1614,8 @@ function addMethod(ctx, name, method) {
|
|
|
1392
1614
|
flag(this, "ssfi", methodWrapper);
|
|
1393
1615
|
}
|
|
1394
1616
|
let result = method.apply(this, arguments);
|
|
1395
|
-
if (result !==
|
|
1396
|
-
|
|
1397
|
-
let newAssertion = new Assertion;
|
|
1617
|
+
if (result !== void 0) return result;
|
|
1618
|
+
let newAssertion = new Assertion();
|
|
1398
1619
|
transferFlags(this, newAssertion);
|
|
1399
1620
|
return newAssertion;
|
|
1400
1621
|
}, "methodWrapper");
|
|
@@ -1404,9 +1625,9 @@ function addMethod(ctx, name, method) {
|
|
|
1404
1625
|
}
|
|
1405
1626
|
__name(addMethod, "addMethod");
|
|
1406
1627
|
function overwriteProperty(ctx, name, getter) {
|
|
1407
|
-
let _get = Object.getOwnPropertyDescriptor(ctx, name), _super = /* @__PURE__ */ __name(function() {
|
|
1408
|
-
|
|
1409
|
-
|
|
1628
|
+
let _get = Object.getOwnPropertyDescriptor(ctx, name), _super = /* @__PURE__ */ __name(function() {
|
|
1629
|
+
}, "_super");
|
|
1630
|
+
if (_get && "function" === typeof _get.get) _super = _get.get;
|
|
1410
1631
|
Object.defineProperty(ctx, name, {
|
|
1411
1632
|
get: /* @__PURE__ */ __name(function overwritingPropertyGetter() {
|
|
1412
1633
|
if (!isProxyEnabled() && !flag(this, "lockSsfi")) {
|
|
@@ -1416,10 +1637,10 @@ function overwriteProperty(ctx, name, getter) {
|
|
|
1416
1637
|
flag(this, "lockSsfi", true);
|
|
1417
1638
|
let result = getter(_super).call(this);
|
|
1418
1639
|
flag(this, "lockSsfi", origLockSsfi);
|
|
1419
|
-
if (result !==
|
|
1640
|
+
if (result !== void 0) {
|
|
1420
1641
|
return result;
|
|
1421
1642
|
}
|
|
1422
|
-
let newAssertion = new Assertion;
|
|
1643
|
+
let newAssertion = new Assertion();
|
|
1423
1644
|
transferFlags(this, newAssertion);
|
|
1424
1645
|
return newAssertion;
|
|
1425
1646
|
}, "overwritingPropertyGetter"),
|
|
@@ -1431,8 +1652,7 @@ function overwriteMethod(ctx, name, method) {
|
|
|
1431
1652
|
let _method = ctx[name], _super = /* @__PURE__ */ __name(function() {
|
|
1432
1653
|
throw new Error(name + " is not a function");
|
|
1433
1654
|
}, "_super");
|
|
1434
|
-
if (_method && typeof _method
|
|
1435
|
-
_super = _method;
|
|
1655
|
+
if (_method && "function" === typeof _method) _super = _method;
|
|
1436
1656
|
let overwritingMethodWrapper = /* @__PURE__ */ __name(function() {
|
|
1437
1657
|
if (!flag(this, "lockSsfi")) {
|
|
1438
1658
|
flag(this, "ssfi", overwritingMethodWrapper);
|
|
@@ -1441,10 +1661,10 @@ function overwriteMethod(ctx, name, method) {
|
|
|
1441
1661
|
flag(this, "lockSsfi", true);
|
|
1442
1662
|
let result = method(_super).apply(this, arguments);
|
|
1443
1663
|
flag(this, "lockSsfi", origLockSsfi);
|
|
1444
|
-
if (result !==
|
|
1664
|
+
if (result !== void 0) {
|
|
1445
1665
|
return result;
|
|
1446
1666
|
}
|
|
1447
|
-
let newAssertion = new Assertion;
|
|
1667
|
+
let newAssertion = new Assertion();
|
|
1448
1668
|
transferFlags(this, newAssertion);
|
|
1449
1669
|
return newAssertion;
|
|
1450
1670
|
}, "overwritingMethodWrapper");
|
|
@@ -1453,11 +1673,11 @@ function overwriteMethod(ctx, name, method) {
|
|
|
1453
1673
|
}
|
|
1454
1674
|
__name(overwriteMethod, "overwriteMethod");
|
|
1455
1675
|
var canSetPrototype = typeof Object.setPrototypeOf === "function";
|
|
1456
|
-
var testFn = /* @__PURE__ */ __name(function() {
|
|
1676
|
+
var testFn = /* @__PURE__ */ __name(function() {
|
|
1677
|
+
}, "testFn");
|
|
1457
1678
|
var excludeNames = Object.getOwnPropertyNames(testFn).filter(function(name) {
|
|
1458
1679
|
let propDesc = Object.getOwnPropertyDescriptor(testFn, name);
|
|
1459
|
-
if (typeof propDesc !== "object")
|
|
1460
|
-
return true;
|
|
1680
|
+
if (typeof propDesc !== "object") return true;
|
|
1461
1681
|
return !propDesc.configurable;
|
|
1462
1682
|
});
|
|
1463
1683
|
var call = Function.prototype.call;
|
|
@@ -1472,7 +1692,8 @@ __name(_PluginAddChainableMethodEvent, "PluginAddChainableMethodEvent");
|
|
|
1472
1692
|
var PluginAddChainableMethodEvent = _PluginAddChainableMethodEvent;
|
|
1473
1693
|
function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
1474
1694
|
if (typeof chainingBehavior !== "function") {
|
|
1475
|
-
chainingBehavior = /* @__PURE__ */ __name(function() {
|
|
1695
|
+
chainingBehavior = /* @__PURE__ */ __name(function() {
|
|
1696
|
+
}, "chainingBehavior");
|
|
1476
1697
|
}
|
|
1477
1698
|
let chainableBehavior = {
|
|
1478
1699
|
method,
|
|
@@ -1490,10 +1711,10 @@ function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
|
1490
1711
|
flag(this, "ssfi", chainableMethodWrapper);
|
|
1491
1712
|
}
|
|
1492
1713
|
let result = chainableBehavior.method.apply(this, arguments);
|
|
1493
|
-
if (result !==
|
|
1714
|
+
if (result !== void 0) {
|
|
1494
1715
|
return result;
|
|
1495
1716
|
}
|
|
1496
|
-
let newAssertion = new Assertion;
|
|
1717
|
+
let newAssertion = new Assertion();
|
|
1497
1718
|
transferFlags(this, newAssertion);
|
|
1498
1719
|
return newAssertion;
|
|
1499
1720
|
}, "chainableMethodWrapper");
|
|
@@ -1518,7 +1739,14 @@ function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
|
1518
1739
|
}, "chainableMethodGetter"),
|
|
1519
1740
|
configurable: true
|
|
1520
1741
|
});
|
|
1521
|
-
events.dispatchEvent(
|
|
1742
|
+
events.dispatchEvent(
|
|
1743
|
+
new PluginAddChainableMethodEvent(
|
|
1744
|
+
"addChainableMethod",
|
|
1745
|
+
name,
|
|
1746
|
+
method,
|
|
1747
|
+
chainingBehavior
|
|
1748
|
+
)
|
|
1749
|
+
);
|
|
1522
1750
|
}
|
|
1523
1751
|
__name(addChainableMethod, "addChainableMethod");
|
|
1524
1752
|
function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
|
|
@@ -1526,20 +1754,20 @@ function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
|
|
|
1526
1754
|
let _chainingBehavior = chainableBehavior.chainingBehavior;
|
|
1527
1755
|
chainableBehavior.chainingBehavior = /* @__PURE__ */ __name(function overwritingChainableMethodGetter() {
|
|
1528
1756
|
let result = chainingBehavior(_chainingBehavior).call(this);
|
|
1529
|
-
if (result !==
|
|
1757
|
+
if (result !== void 0) {
|
|
1530
1758
|
return result;
|
|
1531
1759
|
}
|
|
1532
|
-
let newAssertion = new Assertion;
|
|
1760
|
+
let newAssertion = new Assertion();
|
|
1533
1761
|
transferFlags(this, newAssertion);
|
|
1534
1762
|
return newAssertion;
|
|
1535
1763
|
}, "overwritingChainableMethodGetter");
|
|
1536
1764
|
let _method = chainableBehavior.method;
|
|
1537
1765
|
chainableBehavior.method = /* @__PURE__ */ __name(function overwritingChainableMethodWrapper() {
|
|
1538
1766
|
let result = method(_method).apply(this, arguments);
|
|
1539
|
-
if (result !==
|
|
1767
|
+
if (result !== void 0) {
|
|
1540
1768
|
return result;
|
|
1541
1769
|
}
|
|
1542
|
-
let newAssertion = new Assertion;
|
|
1770
|
+
let newAssertion = new Assertion();
|
|
1543
1771
|
transferFlags(this, newAssertion);
|
|
1544
1772
|
return newAssertion;
|
|
1545
1773
|
}, "overwritingChainableMethodWrapper");
|
|
@@ -1550,8 +1778,7 @@ function compareByInspect(a, b) {
|
|
|
1550
1778
|
}
|
|
1551
1779
|
__name(compareByInspect, "compareByInspect");
|
|
1552
1780
|
function getOwnEnumerablePropertySymbols(obj) {
|
|
1553
|
-
if (typeof Object.getOwnPropertySymbols !== "function")
|
|
1554
|
-
return [];
|
|
1781
|
+
if (typeof Object.getOwnPropertySymbols !== "function") return [];
|
|
1555
1782
|
return Object.getOwnPropertySymbols(obj).filter(function(sym) {
|
|
1556
1783
|
return Object.getOwnPropertyDescriptor(obj, sym).enumerable;
|
|
1557
1784
|
});
|
|
@@ -1576,14 +1803,13 @@ function getOperator(obj, args) {
|
|
|
1576
1803
|
if (operator) {
|
|
1577
1804
|
return operator;
|
|
1578
1805
|
}
|
|
1579
|
-
if (typeof msg === "function")
|
|
1580
|
-
msg = msg();
|
|
1806
|
+
if (typeof msg === "function") msg = msg();
|
|
1581
1807
|
msg = msg || "";
|
|
1582
1808
|
if (!msg) {
|
|
1583
|
-
return;
|
|
1809
|
+
return void 0;
|
|
1584
1810
|
}
|
|
1585
1811
|
if (/\shave\s/.test(msg)) {
|
|
1586
|
-
return;
|
|
1812
|
+
return void 0;
|
|
1587
1813
|
}
|
|
1588
1814
|
let isObject = isObjectType(expected);
|
|
1589
1815
|
if (/\snot\s/.test(msg)) {
|
|
@@ -1661,15 +1887,22 @@ var functionTypes = {
|
|
|
1661
1887
|
asyncgeneratorfunction: ["asyncgeneratorfunction"]
|
|
1662
1888
|
};
|
|
1663
1889
|
function an(type3, msg) {
|
|
1664
|
-
if (msg)
|
|
1665
|
-
flag2(this, "message", msg);
|
|
1890
|
+
if (msg) flag2(this, "message", msg);
|
|
1666
1891
|
type3 = type3.toLowerCase();
|
|
1667
1892
|
let obj = flag2(this, "object"), article = ~["a", "e", "i", "o", "u"].indexOf(type3.charAt(0)) ? "an " : "a ";
|
|
1668
1893
|
const detectedType = type(obj).toLowerCase();
|
|
1669
1894
|
if (functionTypes["function"].includes(type3)) {
|
|
1670
|
-
this.assert(
|
|
1895
|
+
this.assert(
|
|
1896
|
+
functionTypes[type3].includes(detectedType),
|
|
1897
|
+
"expected #{this} to be " + article + type3,
|
|
1898
|
+
"expected #{this} not to be " + article + type3
|
|
1899
|
+
);
|
|
1671
1900
|
} else {
|
|
1672
|
-
this.assert(
|
|
1901
|
+
this.assert(
|
|
1902
|
+
type3 === detectedType,
|
|
1903
|
+
"expected #{this} to be " + article + type3,
|
|
1904
|
+
"expected #{this} not to be " + article + type3
|
|
1905
|
+
);
|
|
1673
1906
|
}
|
|
1674
1907
|
}
|
|
1675
1908
|
__name(an, "an");
|
|
@@ -1684,8 +1917,7 @@ function includeChainingBehavior() {
|
|
|
1684
1917
|
}
|
|
1685
1918
|
__name(includeChainingBehavior, "includeChainingBehavior");
|
|
1686
1919
|
function include(val, msg) {
|
|
1687
|
-
if (msg)
|
|
1688
|
-
flag2(this, "message", msg);
|
|
1920
|
+
if (msg) flag2(this, "message", msg);
|
|
1689
1921
|
let obj = flag2(this, "object"), objType = type(obj).toLowerCase(), flagMsg = flag2(this, "message"), negate = flag2(this, "negate"), ssfi = flag2(this, "ssfi"), isDeep = flag2(this, "deep"), descriptor = isDeep ? "deep " : "", isEql = isDeep ? flag2(this, "eql") : SameValueZero;
|
|
1690
1922
|
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
1691
1923
|
let included = false;
|
|
@@ -1695,7 +1927,11 @@ function include(val, msg) {
|
|
|
1695
1927
|
break;
|
|
1696
1928
|
case "weakset":
|
|
1697
1929
|
if (isDeep) {
|
|
1698
|
-
throw new AssertionError(
|
|
1930
|
+
throw new AssertionError(
|
|
1931
|
+
flagMsg + "unable to use .deep.include with WeakSet",
|
|
1932
|
+
void 0,
|
|
1933
|
+
ssfi
|
|
1934
|
+
);
|
|
1699
1935
|
}
|
|
1700
1936
|
included = obj.has(val);
|
|
1701
1937
|
break;
|
|
@@ -1724,7 +1960,11 @@ function include(val, msg) {
|
|
|
1724
1960
|
break;
|
|
1725
1961
|
default: {
|
|
1726
1962
|
if (val !== Object(val)) {
|
|
1727
|
-
throw new AssertionError(
|
|
1963
|
+
throw new AssertionError(
|
|
1964
|
+
flagMsg + "the given combination of arguments (" + objType + " and " + type(val).toLowerCase() + ") is invalid for this assertion. You can use an array, a map, an object, a set, a string, or a weakset instead of a " + type(val).toLowerCase(),
|
|
1965
|
+
void 0,
|
|
1966
|
+
ssfi
|
|
1967
|
+
);
|
|
1728
1968
|
}
|
|
1729
1969
|
let props = Object.keys(val);
|
|
1730
1970
|
let firstErr = null;
|
|
@@ -1743,8 +1983,7 @@ function include(val, msg) {
|
|
|
1743
1983
|
if (!check_error_exports.compatibleConstructor(err, AssertionError)) {
|
|
1744
1984
|
throw err;
|
|
1745
1985
|
}
|
|
1746
|
-
if (firstErr === null)
|
|
1747
|
-
firstErr = err;
|
|
1986
|
+
if (firstErr === null) firstErr = err;
|
|
1748
1987
|
numErrs++;
|
|
1749
1988
|
}
|
|
1750
1989
|
}, this);
|
|
@@ -1754,7 +1993,11 @@ function include(val, msg) {
|
|
|
1754
1993
|
return;
|
|
1755
1994
|
}
|
|
1756
1995
|
}
|
|
1757
|
-
this.assert(
|
|
1996
|
+
this.assert(
|
|
1997
|
+
included,
|
|
1998
|
+
"expected #{this} to " + descriptor + "include " + inspect2(val),
|
|
1999
|
+
"expected #{this} to not " + descriptor + "include " + inspect2(val)
|
|
2000
|
+
);
|
|
1758
2001
|
}
|
|
1759
2002
|
__name(include, "include");
|
|
1760
2003
|
Assertion.addChainableMethod("include", include, includeChainingBehavior);
|
|
@@ -1762,14 +2005,28 @@ Assertion.addChainableMethod("contain", include, includeChainingBehavior);
|
|
|
1762
2005
|
Assertion.addChainableMethod("contains", include, includeChainingBehavior);
|
|
1763
2006
|
Assertion.addChainableMethod("includes", include, includeChainingBehavior);
|
|
1764
2007
|
Assertion.addProperty("ok", function() {
|
|
1765
|
-
this.assert(
|
|
2008
|
+
this.assert(
|
|
2009
|
+
flag2(this, "object"),
|
|
2010
|
+
"expected #{this} to be truthy",
|
|
2011
|
+
"expected #{this} to be falsy"
|
|
2012
|
+
);
|
|
1766
2013
|
});
|
|
1767
2014
|
Assertion.addProperty("true", function() {
|
|
1768
|
-
this.assert(
|
|
2015
|
+
this.assert(
|
|
2016
|
+
true === flag2(this, "object"),
|
|
2017
|
+
"expected #{this} to be true",
|
|
2018
|
+
"expected #{this} to be false",
|
|
2019
|
+
flag2(this, "negate") ? false : true
|
|
2020
|
+
);
|
|
1769
2021
|
});
|
|
1770
2022
|
Assertion.addProperty("numeric", function() {
|
|
1771
2023
|
const object = flag2(this, "object");
|
|
1772
|
-
this.assert(
|
|
2024
|
+
this.assert(
|
|
2025
|
+
["Number", "BigInt"].includes(type(object)),
|
|
2026
|
+
"expected #{this} to be numeric",
|
|
2027
|
+
"expected #{this} to not be numeric",
|
|
2028
|
+
flag2(this, "negate") ? false : true
|
|
2029
|
+
);
|
|
1773
2030
|
});
|
|
1774
2031
|
Assertion.addProperty("callable", function() {
|
|
1775
2032
|
const val = flag2(this, "object");
|
|
@@ -1785,24 +2042,45 @@ Assertion.addProperty("callable", function() {
|
|
|
1785
2042
|
"AsyncGeneratorFunction"
|
|
1786
2043
|
].includes(type(val));
|
|
1787
2044
|
if (isCallable && negate || !isCallable && !negate) {
|
|
1788
|
-
throw new AssertionError(assertionMessage,
|
|
2045
|
+
throw new AssertionError(assertionMessage, void 0, ssfi);
|
|
1789
2046
|
}
|
|
1790
2047
|
});
|
|
1791
2048
|
Assertion.addProperty("false", function() {
|
|
1792
|
-
this.assert(
|
|
2049
|
+
this.assert(
|
|
2050
|
+
false === flag2(this, "object"),
|
|
2051
|
+
"expected #{this} to be false",
|
|
2052
|
+
"expected #{this} to be true",
|
|
2053
|
+
flag2(this, "negate") ? true : false
|
|
2054
|
+
);
|
|
1793
2055
|
});
|
|
1794
2056
|
Assertion.addProperty("null", function() {
|
|
1795
|
-
this.assert(
|
|
2057
|
+
this.assert(
|
|
2058
|
+
null === flag2(this, "object"),
|
|
2059
|
+
"expected #{this} to be null",
|
|
2060
|
+
"expected #{this} not to be null"
|
|
2061
|
+
);
|
|
1796
2062
|
});
|
|
1797
2063
|
Assertion.addProperty("undefined", function() {
|
|
1798
|
-
this.assert(
|
|
2064
|
+
this.assert(
|
|
2065
|
+
void 0 === flag2(this, "object"),
|
|
2066
|
+
"expected #{this} to be undefined",
|
|
2067
|
+
"expected #{this} not to be undefined"
|
|
2068
|
+
);
|
|
1799
2069
|
});
|
|
1800
2070
|
Assertion.addProperty("NaN", function() {
|
|
1801
|
-
this.assert(
|
|
2071
|
+
this.assert(
|
|
2072
|
+
isNaN2(flag2(this, "object")),
|
|
2073
|
+
"expected #{this} to be NaN",
|
|
2074
|
+
"expected #{this} not to be NaN"
|
|
2075
|
+
);
|
|
1802
2076
|
});
|
|
1803
2077
|
function assertExist() {
|
|
1804
2078
|
let val = flag2(this, "object");
|
|
1805
|
-
this.assert(
|
|
2079
|
+
this.assert(
|
|
2080
|
+
val !== null && val !== void 0,
|
|
2081
|
+
"expected #{this} to exist",
|
|
2082
|
+
"expected #{this} to not exist"
|
|
2083
|
+
);
|
|
1806
2084
|
}
|
|
1807
2085
|
__name(assertExist, "assertExist");
|
|
1808
2086
|
Assertion.addProperty("exist", assertExist);
|
|
@@ -1821,29 +2099,44 @@ Assertion.addProperty("empty", function() {
|
|
|
1821
2099
|
break;
|
|
1822
2100
|
case "weakmap":
|
|
1823
2101
|
case "weakset":
|
|
1824
|
-
throw new AssertionError(
|
|
2102
|
+
throw new AssertionError(
|
|
2103
|
+
flagMsg + ".empty was passed a weak collection",
|
|
2104
|
+
void 0,
|
|
2105
|
+
ssfi
|
|
2106
|
+
);
|
|
1825
2107
|
case "function": {
|
|
1826
2108
|
const msg = flagMsg + ".empty was passed a function " + getName(val);
|
|
1827
|
-
throw new AssertionError(msg.trim(),
|
|
2109
|
+
throw new AssertionError(msg.trim(), void 0, ssfi);
|
|
1828
2110
|
}
|
|
1829
2111
|
default:
|
|
1830
2112
|
if (val !== Object(val)) {
|
|
1831
|
-
throw new AssertionError(
|
|
2113
|
+
throw new AssertionError(
|
|
2114
|
+
flagMsg + ".empty was passed non-string primitive " + inspect2(val),
|
|
2115
|
+
void 0,
|
|
2116
|
+
ssfi
|
|
2117
|
+
);
|
|
1832
2118
|
}
|
|
1833
2119
|
itemsCount = Object.keys(val).length;
|
|
1834
2120
|
}
|
|
1835
|
-
this.assert(
|
|
2121
|
+
this.assert(
|
|
2122
|
+
0 === itemsCount,
|
|
2123
|
+
"expected #{this} to be empty",
|
|
2124
|
+
"expected #{this} not to be empty"
|
|
2125
|
+
);
|
|
1836
2126
|
});
|
|
1837
2127
|
function checkArguments() {
|
|
1838
2128
|
let obj = flag2(this, "object"), type3 = type(obj);
|
|
1839
|
-
this.assert(
|
|
2129
|
+
this.assert(
|
|
2130
|
+
"Arguments" === type3,
|
|
2131
|
+
"expected #{this} to be arguments but got " + type3,
|
|
2132
|
+
"expected #{this} to not be arguments"
|
|
2133
|
+
);
|
|
1840
2134
|
}
|
|
1841
2135
|
__name(checkArguments, "checkArguments");
|
|
1842
2136
|
Assertion.addProperty("arguments", checkArguments);
|
|
1843
2137
|
Assertion.addProperty("Arguments", checkArguments);
|
|
1844
2138
|
function assertEqual(val, msg) {
|
|
1845
|
-
if (msg)
|
|
1846
|
-
flag2(this, "message", msg);
|
|
2139
|
+
if (msg) flag2(this, "message", msg);
|
|
1847
2140
|
let obj = flag2(this, "object");
|
|
1848
2141
|
if (flag2(this, "deep")) {
|
|
1849
2142
|
let prevLockSsfi = flag2(this, "lockSsfi");
|
|
@@ -1851,7 +2144,14 @@ function assertEqual(val, msg) {
|
|
|
1851
2144
|
this.eql(val);
|
|
1852
2145
|
flag2(this, "lockSsfi", prevLockSsfi);
|
|
1853
2146
|
} else {
|
|
1854
|
-
this.assert(
|
|
2147
|
+
this.assert(
|
|
2148
|
+
val === obj,
|
|
2149
|
+
"expected #{this} to equal #{exp}",
|
|
2150
|
+
"expected #{this} to not equal #{exp}",
|
|
2151
|
+
val,
|
|
2152
|
+
this._obj,
|
|
2153
|
+
true
|
|
2154
|
+
);
|
|
1855
2155
|
}
|
|
1856
2156
|
}
|
|
1857
2157
|
__name(assertEqual, "assertEqual");
|
|
@@ -1859,28 +2159,45 @@ Assertion.addMethod("equal", assertEqual);
|
|
|
1859
2159
|
Assertion.addMethod("equals", assertEqual);
|
|
1860
2160
|
Assertion.addMethod("eq", assertEqual);
|
|
1861
2161
|
function assertEql(obj, msg) {
|
|
1862
|
-
if (msg)
|
|
1863
|
-
flag2(this, "message", msg);
|
|
2162
|
+
if (msg) flag2(this, "message", msg);
|
|
1864
2163
|
let eql = flag2(this, "eql");
|
|
1865
|
-
this.assert(
|
|
2164
|
+
this.assert(
|
|
2165
|
+
eql(obj, flag2(this, "object")),
|
|
2166
|
+
"expected #{this} to deeply equal #{exp}",
|
|
2167
|
+
"expected #{this} to not deeply equal #{exp}",
|
|
2168
|
+
obj,
|
|
2169
|
+
this._obj,
|
|
2170
|
+
true
|
|
2171
|
+
);
|
|
1866
2172
|
}
|
|
1867
2173
|
__name(assertEql, "assertEql");
|
|
1868
2174
|
Assertion.addMethod("eql", assertEql);
|
|
1869
2175
|
Assertion.addMethod("eqls", assertEql);
|
|
1870
2176
|
function assertAbove(n, msg) {
|
|
1871
|
-
if (msg)
|
|
1872
|
-
flag2(this, "message", msg);
|
|
2177
|
+
if (msg) flag2(this, "message", msg);
|
|
1873
2178
|
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), nType = type(n).toLowerCase();
|
|
1874
2179
|
if (doLength && objType !== "map" && objType !== "set") {
|
|
1875
2180
|
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
1876
2181
|
}
|
|
1877
2182
|
if (!doLength && objType === "date" && nType !== "date") {
|
|
1878
|
-
throw new AssertionError(
|
|
2183
|
+
throw new AssertionError(
|
|
2184
|
+
msgPrefix + "the argument to above must be a date",
|
|
2185
|
+
void 0,
|
|
2186
|
+
ssfi
|
|
2187
|
+
);
|
|
1879
2188
|
} else if (!isNumeric(n) && (doLength || isNumeric(obj))) {
|
|
1880
|
-
throw new AssertionError(
|
|
2189
|
+
throw new AssertionError(
|
|
2190
|
+
msgPrefix + "the argument to above must be a number",
|
|
2191
|
+
void 0,
|
|
2192
|
+
ssfi
|
|
2193
|
+
);
|
|
1881
2194
|
} else if (!doLength && objType !== "date" && !isNumeric(obj)) {
|
|
1882
2195
|
let printObj = objType === "string" ? "'" + obj + "'" : obj;
|
|
1883
|
-
throw new AssertionError(
|
|
2196
|
+
throw new AssertionError(
|
|
2197
|
+
msgPrefix + "expected " + printObj + " to be a number or a date",
|
|
2198
|
+
void 0,
|
|
2199
|
+
ssfi
|
|
2200
|
+
);
|
|
1884
2201
|
}
|
|
1885
2202
|
if (doLength) {
|
|
1886
2203
|
let descriptor = "length", itemsCount;
|
|
@@ -1890,9 +2207,20 @@ function assertAbove(n, msg) {
|
|
|
1890
2207
|
} else {
|
|
1891
2208
|
itemsCount = obj.length;
|
|
1892
2209
|
}
|
|
1893
|
-
this.assert(
|
|
2210
|
+
this.assert(
|
|
2211
|
+
itemsCount > n,
|
|
2212
|
+
"expected #{this} to have a " + descriptor + " above #{exp} but got #{act}",
|
|
2213
|
+
"expected #{this} to not have a " + descriptor + " above #{exp}",
|
|
2214
|
+
n,
|
|
2215
|
+
itemsCount
|
|
2216
|
+
);
|
|
1894
2217
|
} else {
|
|
1895
|
-
this.assert(
|
|
2218
|
+
this.assert(
|
|
2219
|
+
obj > n,
|
|
2220
|
+
"expected #{this} to be above #{exp}",
|
|
2221
|
+
"expected #{this} to be at most #{exp}",
|
|
2222
|
+
n
|
|
2223
|
+
);
|
|
1896
2224
|
}
|
|
1897
2225
|
}
|
|
1898
2226
|
__name(assertAbove, "assertAbove");
|
|
@@ -1900,8 +2228,7 @@ Assertion.addMethod("above", assertAbove);
|
|
|
1900
2228
|
Assertion.addMethod("gt", assertAbove);
|
|
1901
2229
|
Assertion.addMethod("greaterThan", assertAbove);
|
|
1902
2230
|
function assertLeast(n, msg) {
|
|
1903
|
-
if (msg)
|
|
1904
|
-
flag2(this, "message", msg);
|
|
2231
|
+
if (msg) flag2(this, "message", msg);
|
|
1905
2232
|
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), nType = type(n).toLowerCase(), errorMessage, shouldThrow = true;
|
|
1906
2233
|
if (doLength && objType !== "map" && objType !== "set") {
|
|
1907
2234
|
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
@@ -1917,7 +2244,7 @@ function assertLeast(n, msg) {
|
|
|
1917
2244
|
shouldThrow = false;
|
|
1918
2245
|
}
|
|
1919
2246
|
if (shouldThrow) {
|
|
1920
|
-
throw new AssertionError(errorMessage,
|
|
2247
|
+
throw new AssertionError(errorMessage, void 0, ssfi);
|
|
1921
2248
|
}
|
|
1922
2249
|
if (doLength) {
|
|
1923
2250
|
let descriptor = "length", itemsCount;
|
|
@@ -1927,9 +2254,20 @@ function assertLeast(n, msg) {
|
|
|
1927
2254
|
} else {
|
|
1928
2255
|
itemsCount = obj.length;
|
|
1929
2256
|
}
|
|
1930
|
-
this.assert(
|
|
2257
|
+
this.assert(
|
|
2258
|
+
itemsCount >= n,
|
|
2259
|
+
"expected #{this} to have a " + descriptor + " at least #{exp} but got #{act}",
|
|
2260
|
+
"expected #{this} to have a " + descriptor + " below #{exp}",
|
|
2261
|
+
n,
|
|
2262
|
+
itemsCount
|
|
2263
|
+
);
|
|
1931
2264
|
} else {
|
|
1932
|
-
this.assert(
|
|
2265
|
+
this.assert(
|
|
2266
|
+
obj >= n,
|
|
2267
|
+
"expected #{this} to be at least #{exp}",
|
|
2268
|
+
"expected #{this} to be below #{exp}",
|
|
2269
|
+
n
|
|
2270
|
+
);
|
|
1933
2271
|
}
|
|
1934
2272
|
}
|
|
1935
2273
|
__name(assertLeast, "assertLeast");
|
|
@@ -1937,8 +2275,7 @@ Assertion.addMethod("least", assertLeast);
|
|
|
1937
2275
|
Assertion.addMethod("gte", assertLeast);
|
|
1938
2276
|
Assertion.addMethod("greaterThanOrEqual", assertLeast);
|
|
1939
2277
|
function assertBelow(n, msg) {
|
|
1940
|
-
if (msg)
|
|
1941
|
-
flag2(this, "message", msg);
|
|
2278
|
+
if (msg) flag2(this, "message", msg);
|
|
1942
2279
|
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), nType = type(n).toLowerCase(), errorMessage, shouldThrow = true;
|
|
1943
2280
|
if (doLength && objType !== "map" && objType !== "set") {
|
|
1944
2281
|
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
@@ -1954,7 +2291,7 @@ function assertBelow(n, msg) {
|
|
|
1954
2291
|
shouldThrow = false;
|
|
1955
2292
|
}
|
|
1956
2293
|
if (shouldThrow) {
|
|
1957
|
-
throw new AssertionError(errorMessage,
|
|
2294
|
+
throw new AssertionError(errorMessage, void 0, ssfi);
|
|
1958
2295
|
}
|
|
1959
2296
|
if (doLength) {
|
|
1960
2297
|
let descriptor = "length", itemsCount;
|
|
@@ -1964,9 +2301,20 @@ function assertBelow(n, msg) {
|
|
|
1964
2301
|
} else {
|
|
1965
2302
|
itemsCount = obj.length;
|
|
1966
2303
|
}
|
|
1967
|
-
this.assert(
|
|
2304
|
+
this.assert(
|
|
2305
|
+
itemsCount < n,
|
|
2306
|
+
"expected #{this} to have a " + descriptor + " below #{exp} but got #{act}",
|
|
2307
|
+
"expected #{this} to not have a " + descriptor + " below #{exp}",
|
|
2308
|
+
n,
|
|
2309
|
+
itemsCount
|
|
2310
|
+
);
|
|
1968
2311
|
} else {
|
|
1969
|
-
this.assert(
|
|
2312
|
+
this.assert(
|
|
2313
|
+
obj < n,
|
|
2314
|
+
"expected #{this} to be below #{exp}",
|
|
2315
|
+
"expected #{this} to be at least #{exp}",
|
|
2316
|
+
n
|
|
2317
|
+
);
|
|
1970
2318
|
}
|
|
1971
2319
|
}
|
|
1972
2320
|
__name(assertBelow, "assertBelow");
|
|
@@ -1974,8 +2322,7 @@ Assertion.addMethod("below", assertBelow);
|
|
|
1974
2322
|
Assertion.addMethod("lt", assertBelow);
|
|
1975
2323
|
Assertion.addMethod("lessThan", assertBelow);
|
|
1976
2324
|
function assertMost(n, msg) {
|
|
1977
|
-
if (msg)
|
|
1978
|
-
flag2(this, "message", msg);
|
|
2325
|
+
if (msg) flag2(this, "message", msg);
|
|
1979
2326
|
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), nType = type(n).toLowerCase(), errorMessage, shouldThrow = true;
|
|
1980
2327
|
if (doLength && objType !== "map" && objType !== "set") {
|
|
1981
2328
|
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
@@ -1991,7 +2338,7 @@ function assertMost(n, msg) {
|
|
|
1991
2338
|
shouldThrow = false;
|
|
1992
2339
|
}
|
|
1993
2340
|
if (shouldThrow) {
|
|
1994
|
-
throw new AssertionError(errorMessage,
|
|
2341
|
+
throw new AssertionError(errorMessage, void 0, ssfi);
|
|
1995
2342
|
}
|
|
1996
2343
|
if (doLength) {
|
|
1997
2344
|
let descriptor = "length", itemsCount;
|
|
@@ -2001,9 +2348,20 @@ function assertMost(n, msg) {
|
|
|
2001
2348
|
} else {
|
|
2002
2349
|
itemsCount = obj.length;
|
|
2003
2350
|
}
|
|
2004
|
-
this.assert(
|
|
2351
|
+
this.assert(
|
|
2352
|
+
itemsCount <= n,
|
|
2353
|
+
"expected #{this} to have a " + descriptor + " at most #{exp} but got #{act}",
|
|
2354
|
+
"expected #{this} to have a " + descriptor + " above #{exp}",
|
|
2355
|
+
n,
|
|
2356
|
+
itemsCount
|
|
2357
|
+
);
|
|
2005
2358
|
} else {
|
|
2006
|
-
this.assert(
|
|
2359
|
+
this.assert(
|
|
2360
|
+
obj <= n,
|
|
2361
|
+
"expected #{this} to be at most #{exp}",
|
|
2362
|
+
"expected #{this} to be above #{exp}",
|
|
2363
|
+
n
|
|
2364
|
+
);
|
|
2007
2365
|
}
|
|
2008
2366
|
}
|
|
2009
2367
|
__name(assertMost, "assertMost");
|
|
@@ -2011,8 +2369,7 @@ Assertion.addMethod("most", assertMost);
|
|
|
2011
2369
|
Assertion.addMethod("lte", assertMost);
|
|
2012
2370
|
Assertion.addMethod("lessThanOrEqual", assertMost);
|
|
2013
2371
|
Assertion.addMethod("within", function(start, finish, msg) {
|
|
2014
|
-
if (msg)
|
|
2015
|
-
flag2(this, "message", msg);
|
|
2372
|
+
if (msg) flag2(this, "message", msg);
|
|
2016
2373
|
let obj = flag2(this, "object"), doLength = flag2(this, "doLength"), flagMsg = flag2(this, "message"), msgPrefix = flagMsg ? flagMsg + ": " : "", ssfi = flag2(this, "ssfi"), objType = type(obj).toLowerCase(), startType = type(start).toLowerCase(), finishType = type(finish).toLowerCase(), errorMessage, shouldThrow = true, range = startType === "date" && finishType === "date" ? start.toISOString() + ".." + finish.toISOString() : start + ".." + finish;
|
|
2017
2374
|
if (doLength && objType !== "map" && objType !== "set") {
|
|
2018
2375
|
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
@@ -2028,7 +2385,7 @@ Assertion.addMethod("within", function(start, finish, msg) {
|
|
|
2028
2385
|
shouldThrow = false;
|
|
2029
2386
|
}
|
|
2030
2387
|
if (shouldThrow) {
|
|
2031
|
-
throw new AssertionError(errorMessage,
|
|
2388
|
+
throw new AssertionError(errorMessage, void 0, ssfi);
|
|
2032
2389
|
}
|
|
2033
2390
|
if (doLength) {
|
|
2034
2391
|
let descriptor = "length", itemsCount;
|
|
@@ -2038,14 +2395,21 @@ Assertion.addMethod("within", function(start, finish, msg) {
|
|
|
2038
2395
|
} else {
|
|
2039
2396
|
itemsCount = obj.length;
|
|
2040
2397
|
}
|
|
2041
|
-
this.assert(
|
|
2398
|
+
this.assert(
|
|
2399
|
+
itemsCount >= start && itemsCount <= finish,
|
|
2400
|
+
"expected #{this} to have a " + descriptor + " within " + range,
|
|
2401
|
+
"expected #{this} to not have a " + descriptor + " within " + range
|
|
2402
|
+
);
|
|
2042
2403
|
} else {
|
|
2043
|
-
this.assert(
|
|
2404
|
+
this.assert(
|
|
2405
|
+
obj >= start && obj <= finish,
|
|
2406
|
+
"expected #{this} to be within " + range,
|
|
2407
|
+
"expected #{this} to not be within " + range
|
|
2408
|
+
);
|
|
2044
2409
|
}
|
|
2045
2410
|
});
|
|
2046
2411
|
function assertInstanceOf(constructor, msg) {
|
|
2047
|
-
if (msg)
|
|
2048
|
-
flag2(this, "message", msg);
|
|
2412
|
+
if (msg) flag2(this, "message", msg);
|
|
2049
2413
|
let target = flag2(this, "object");
|
|
2050
2414
|
let ssfi = flag2(this, "ssfi");
|
|
2051
2415
|
let flagMsg = flag2(this, "message");
|
|
@@ -2055,7 +2419,11 @@ function assertInstanceOf(constructor, msg) {
|
|
|
2055
2419
|
} catch (err) {
|
|
2056
2420
|
if (err instanceof TypeError) {
|
|
2057
2421
|
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
2058
|
-
throw new AssertionError(
|
|
2422
|
+
throw new AssertionError(
|
|
2423
|
+
flagMsg + "The instanceof assertion needs a constructor but " + type(constructor) + " was given.",
|
|
2424
|
+
void 0,
|
|
2425
|
+
ssfi
|
|
2426
|
+
);
|
|
2059
2427
|
}
|
|
2060
2428
|
throw err;
|
|
2061
2429
|
}
|
|
@@ -2063,52 +2431,75 @@ function assertInstanceOf(constructor, msg) {
|
|
|
2063
2431
|
if (name == null) {
|
|
2064
2432
|
name = "an unnamed constructor";
|
|
2065
2433
|
}
|
|
2066
|
-
this.assert(
|
|
2434
|
+
this.assert(
|
|
2435
|
+
isInstanceOf,
|
|
2436
|
+
"expected #{this} to be an instance of " + name,
|
|
2437
|
+
"expected #{this} to not be an instance of " + name
|
|
2438
|
+
);
|
|
2067
2439
|
}
|
|
2068
2440
|
__name(assertInstanceOf, "assertInstanceOf");
|
|
2069
2441
|
Assertion.addMethod("instanceof", assertInstanceOf);
|
|
2070
2442
|
Assertion.addMethod("instanceOf", assertInstanceOf);
|
|
2071
2443
|
function assertProperty(name, val, msg) {
|
|
2072
|
-
if (msg)
|
|
2073
|
-
flag2(this, "message", msg);
|
|
2444
|
+
if (msg) flag2(this, "message", msg);
|
|
2074
2445
|
let isNested = flag2(this, "nested"), isOwn = flag2(this, "own"), flagMsg = flag2(this, "message"), obj = flag2(this, "object"), ssfi = flag2(this, "ssfi"), nameType = typeof name;
|
|
2075
2446
|
flagMsg = flagMsg ? flagMsg + ": " : "";
|
|
2076
2447
|
if (isNested) {
|
|
2077
2448
|
if (nameType !== "string") {
|
|
2078
|
-
throw new AssertionError(
|
|
2449
|
+
throw new AssertionError(
|
|
2450
|
+
flagMsg + "the argument to property must be a string when using nested syntax",
|
|
2451
|
+
void 0,
|
|
2452
|
+
ssfi
|
|
2453
|
+
);
|
|
2079
2454
|
}
|
|
2080
2455
|
} else {
|
|
2081
2456
|
if (nameType !== "string" && nameType !== "number" && nameType !== "symbol") {
|
|
2082
|
-
throw new AssertionError(
|
|
2457
|
+
throw new AssertionError(
|
|
2458
|
+
flagMsg + "the argument to property must be a string, number, or symbol",
|
|
2459
|
+
void 0,
|
|
2460
|
+
ssfi
|
|
2461
|
+
);
|
|
2083
2462
|
}
|
|
2084
2463
|
}
|
|
2085
2464
|
if (isNested && isOwn) {
|
|
2086
|
-
throw new AssertionError(
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2465
|
+
throw new AssertionError(
|
|
2466
|
+
flagMsg + 'The "nested" and "own" flags cannot be combined.',
|
|
2467
|
+
void 0,
|
|
2468
|
+
ssfi
|
|
2469
|
+
);
|
|
2470
|
+
}
|
|
2471
|
+
if (obj === null || obj === void 0) {
|
|
2472
|
+
throw new AssertionError(
|
|
2473
|
+
flagMsg + "Target cannot be null or undefined.",
|
|
2474
|
+
void 0,
|
|
2475
|
+
ssfi
|
|
2476
|
+
);
|
|
2090
2477
|
}
|
|
2091
2478
|
let isDeep = flag2(this, "deep"), negate = flag2(this, "negate"), pathInfo = isNested ? getPathInfo(obj, name) : null, value = isNested ? pathInfo.value : obj[name], isEql = isDeep ? flag2(this, "eql") : (val1, val2) => val1 === val2;
|
|
2092
2479
|
let descriptor = "";
|
|
2093
|
-
if (isDeep)
|
|
2094
|
-
|
|
2095
|
-
if (
|
|
2096
|
-
descriptor += "own ";
|
|
2097
|
-
if (isNested)
|
|
2098
|
-
descriptor += "nested ";
|
|
2480
|
+
if (isDeep) descriptor += "deep ";
|
|
2481
|
+
if (isOwn) descriptor += "own ";
|
|
2482
|
+
if (isNested) descriptor += "nested ";
|
|
2099
2483
|
descriptor += "property ";
|
|
2100
2484
|
let hasProperty2;
|
|
2101
|
-
if (isOwn)
|
|
2102
|
-
|
|
2103
|
-
else
|
|
2104
|
-
hasProperty2 = pathInfo.exists;
|
|
2105
|
-
else
|
|
2106
|
-
hasProperty2 = hasProperty(obj, name);
|
|
2485
|
+
if (isOwn) hasProperty2 = Object.prototype.hasOwnProperty.call(obj, name);
|
|
2486
|
+
else if (isNested) hasProperty2 = pathInfo.exists;
|
|
2487
|
+
else hasProperty2 = hasProperty(obj, name);
|
|
2107
2488
|
if (!negate || arguments.length === 1) {
|
|
2108
|
-
this.assert(
|
|
2489
|
+
this.assert(
|
|
2490
|
+
hasProperty2,
|
|
2491
|
+
"expected #{this} to have " + descriptor + inspect2(name),
|
|
2492
|
+
"expected #{this} to not have " + descriptor + inspect2(name)
|
|
2493
|
+
);
|
|
2109
2494
|
}
|
|
2110
2495
|
if (arguments.length > 1) {
|
|
2111
|
-
this.assert(
|
|
2496
|
+
this.assert(
|
|
2497
|
+
hasProperty2 && isEql(val, value),
|
|
2498
|
+
"expected #{this} to have " + descriptor + inspect2(name) + " of #{exp}, but got #{act}",
|
|
2499
|
+
"expected #{this} to not have " + descriptor + inspect2(name) + " of #{act}",
|
|
2500
|
+
val,
|
|
2501
|
+
value
|
|
2502
|
+
);
|
|
2112
2503
|
}
|
|
2113
2504
|
flag2(this, "object", value);
|
|
2114
2505
|
}
|
|
@@ -2126,15 +2517,25 @@ function assertOwnPropertyDescriptor(name, descriptor, msg) {
|
|
|
2126
2517
|
msg = descriptor;
|
|
2127
2518
|
descriptor = null;
|
|
2128
2519
|
}
|
|
2129
|
-
if (msg)
|
|
2130
|
-
flag2(this, "message", msg);
|
|
2520
|
+
if (msg) flag2(this, "message", msg);
|
|
2131
2521
|
let obj = flag2(this, "object");
|
|
2132
2522
|
let actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
|
|
2133
2523
|
let eql = flag2(this, "eql");
|
|
2134
2524
|
if (actualDescriptor && descriptor) {
|
|
2135
|
-
this.assert(
|
|
2525
|
+
this.assert(
|
|
2526
|
+
eql(descriptor, actualDescriptor),
|
|
2527
|
+
"expected the own property descriptor for " + inspect2(name) + " on #{this} to match " + inspect2(descriptor) + ", got " + inspect2(actualDescriptor),
|
|
2528
|
+
"expected the own property descriptor for " + inspect2(name) + " on #{this} to not match " + inspect2(descriptor),
|
|
2529
|
+
descriptor,
|
|
2530
|
+
actualDescriptor,
|
|
2531
|
+
true
|
|
2532
|
+
);
|
|
2136
2533
|
} else {
|
|
2137
|
-
this.assert(
|
|
2534
|
+
this.assert(
|
|
2535
|
+
actualDescriptor,
|
|
2536
|
+
"expected #{this} to have an own property descriptor for " + inspect2(name),
|
|
2537
|
+
"expected #{this} to not have an own property descriptor for " + inspect2(name)
|
|
2538
|
+
);
|
|
2138
2539
|
}
|
|
2139
2540
|
flag2(this, "object", actualDescriptor);
|
|
2140
2541
|
}
|
|
@@ -2146,8 +2547,7 @@ function assertLengthChain() {
|
|
|
2146
2547
|
}
|
|
2147
2548
|
__name(assertLengthChain, "assertLengthChain");
|
|
2148
2549
|
function assertLength(n, msg) {
|
|
2149
|
-
if (msg)
|
|
2150
|
-
flag2(this, "message", msg);
|
|
2550
|
+
if (msg) flag2(this, "message", msg);
|
|
2151
2551
|
let obj = flag2(this, "object"), objType = type(obj).toLowerCase(), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi"), descriptor = "length", itemsCount;
|
|
2152
2552
|
switch (objType) {
|
|
2153
2553
|
case "map":
|
|
@@ -2159,26 +2559,38 @@ function assertLength(n, msg) {
|
|
|
2159
2559
|
new Assertion(obj, flagMsg, ssfi, true).to.have.property("length");
|
|
2160
2560
|
itemsCount = obj.length;
|
|
2161
2561
|
}
|
|
2162
|
-
this.assert(
|
|
2562
|
+
this.assert(
|
|
2563
|
+
itemsCount == n,
|
|
2564
|
+
"expected #{this} to have a " + descriptor + " of #{exp} but got #{act}",
|
|
2565
|
+
"expected #{this} to not have a " + descriptor + " of #{act}",
|
|
2566
|
+
n,
|
|
2567
|
+
itemsCount
|
|
2568
|
+
);
|
|
2163
2569
|
}
|
|
2164
2570
|
__name(assertLength, "assertLength");
|
|
2165
2571
|
Assertion.addChainableMethod("length", assertLength, assertLengthChain);
|
|
2166
2572
|
Assertion.addChainableMethod("lengthOf", assertLength, assertLengthChain);
|
|
2167
2573
|
function assertMatch(re, msg) {
|
|
2168
|
-
if (msg)
|
|
2169
|
-
flag2(this, "message", msg);
|
|
2574
|
+
if (msg) flag2(this, "message", msg);
|
|
2170
2575
|
let obj = flag2(this, "object");
|
|
2171
|
-
this.assert(
|
|
2576
|
+
this.assert(
|
|
2577
|
+
re.exec(obj),
|
|
2578
|
+
"expected #{this} to match " + re,
|
|
2579
|
+
"expected #{this} not to match " + re
|
|
2580
|
+
);
|
|
2172
2581
|
}
|
|
2173
2582
|
__name(assertMatch, "assertMatch");
|
|
2174
2583
|
Assertion.addMethod("match", assertMatch);
|
|
2175
2584
|
Assertion.addMethod("matches", assertMatch);
|
|
2176
2585
|
Assertion.addMethod("string", function(str, msg) {
|
|
2177
|
-
if (msg)
|
|
2178
|
-
flag2(this, "message", msg);
|
|
2586
|
+
if (msg) flag2(this, "message", msg);
|
|
2179
2587
|
let obj = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
2180
2588
|
new Assertion(obj, flagMsg, ssfi, true).is.a("string");
|
|
2181
|
-
this.assert(
|
|
2589
|
+
this.assert(
|
|
2590
|
+
~obj.indexOf(str),
|
|
2591
|
+
"expected #{this} to contain " + inspect2(str),
|
|
2592
|
+
"expected #{this} to not contain " + inspect2(str)
|
|
2593
|
+
);
|
|
2182
2594
|
});
|
|
2183
2595
|
function assertKeys(keys) {
|
|
2184
2596
|
let obj = flag2(this, "object"), objType = type(obj), keysType = type(keys), ssfi = flag2(this, "ssfi"), isDeep = flag2(this, "deep"), str, deepStr = "", actual, ok = true, flagMsg = flag2(this, "message");
|
|
@@ -2198,12 +2610,12 @@ function assertKeys(keys) {
|
|
|
2198
2610
|
switch (keysType) {
|
|
2199
2611
|
case "Array":
|
|
2200
2612
|
if (arguments.length > 1) {
|
|
2201
|
-
throw new AssertionError(mixedArgsMsg,
|
|
2613
|
+
throw new AssertionError(mixedArgsMsg, void 0, ssfi);
|
|
2202
2614
|
}
|
|
2203
2615
|
break;
|
|
2204
2616
|
case "Object":
|
|
2205
2617
|
if (arguments.length > 1) {
|
|
2206
|
-
throw new AssertionError(mixedArgsMsg,
|
|
2618
|
+
throw new AssertionError(mixedArgsMsg, void 0, ssfi);
|
|
2207
2619
|
}
|
|
2208
2620
|
keys = Object.keys(keys);
|
|
2209
2621
|
break;
|
|
@@ -2215,7 +2627,7 @@ function assertKeys(keys) {
|
|
|
2215
2627
|
});
|
|
2216
2628
|
}
|
|
2217
2629
|
if (!keys.length) {
|
|
2218
|
-
throw new AssertionError(flagMsg + "keys required",
|
|
2630
|
+
throw new AssertionError(flagMsg + "keys required", void 0, ssfi);
|
|
2219
2631
|
}
|
|
2220
2632
|
let len = keys.length, any = flag2(this, "any"), all = flag2(this, "all"), expected = keys, isEql = isDeep ? flag2(this, "eql") : (val1, val2) => val1 === val2;
|
|
2221
2633
|
if (!any && !all) {
|
|
@@ -2254,14 +2666,20 @@ function assertKeys(keys) {
|
|
|
2254
2666
|
}
|
|
2255
2667
|
str = (len > 1 ? "keys " : "key ") + str;
|
|
2256
2668
|
str = (flag2(this, "contains") ? "contain " : "have ") + str;
|
|
2257
|
-
this.assert(
|
|
2669
|
+
this.assert(
|
|
2670
|
+
ok,
|
|
2671
|
+
"expected #{this} to " + deepStr + str,
|
|
2672
|
+
"expected #{this} to not " + deepStr + str,
|
|
2673
|
+
expected.slice(0).sort(compareByInspect),
|
|
2674
|
+
actual.sort(compareByInspect),
|
|
2675
|
+
true
|
|
2676
|
+
);
|
|
2258
2677
|
}
|
|
2259
2678
|
__name(assertKeys, "assertKeys");
|
|
2260
2679
|
Assertion.addMethod("keys", assertKeys);
|
|
2261
2680
|
Assertion.addMethod("key", assertKeys);
|
|
2262
2681
|
function assertThrows(errorLike, errMsgMatcher, msg) {
|
|
2263
|
-
if (msg)
|
|
2264
|
-
flag2(this, "message", msg);
|
|
2682
|
+
if (msg) flag2(this, "message", msg);
|
|
2265
2683
|
let obj = flag2(this, "object"), ssfi = flag2(this, "ssfi"), flagMsg = flag2(this, "message"), negate = flag2(this, "negate") || false;
|
|
2266
2684
|
new Assertion(obj, flagMsg, ssfi, true).is.a("function");
|
|
2267
2685
|
if (isRegExp2(errorLike) || typeof errorLike === "string") {
|
|
@@ -2276,7 +2694,7 @@ function assertThrows(errorLike, errMsgMatcher, msg) {
|
|
|
2276
2694
|
errorWasThrown = true;
|
|
2277
2695
|
caughtErr = err;
|
|
2278
2696
|
}
|
|
2279
|
-
let everyArgIsUndefined = errorLike ===
|
|
2697
|
+
let everyArgIsUndefined = errorLike === void 0 && errMsgMatcher === void 0;
|
|
2280
2698
|
let everyArgIsDefined = Boolean(errorLike && errMsgMatcher);
|
|
2281
2699
|
let errorLikeFail = false;
|
|
2282
2700
|
let errMsgMatcherFail = false;
|
|
@@ -2295,46 +2713,86 @@ function assertThrows(errorLike, errMsgMatcher, msg) {
|
|
|
2295
2713
|
} else if (caughtErr && (typeof caughtErr === "object" || typeof caughtErr === "function")) {
|
|
2296
2714
|
try {
|
|
2297
2715
|
actual = check_error_exports.getConstructorName(caughtErr);
|
|
2298
|
-
} catch (_err) {
|
|
2716
|
+
} catch (_err) {
|
|
2717
|
+
}
|
|
2299
2718
|
}
|
|
2300
|
-
this.assert(
|
|
2719
|
+
this.assert(
|
|
2720
|
+
errorWasThrown,
|
|
2721
|
+
"expected #{this} to throw " + errorLikeString,
|
|
2722
|
+
"expected #{this} to not throw an error but #{act} was thrown",
|
|
2723
|
+
errorLike && errorLike.toString(),
|
|
2724
|
+
actual
|
|
2725
|
+
);
|
|
2301
2726
|
}
|
|
2302
2727
|
if (errorLike && caughtErr) {
|
|
2303
2728
|
if (errorLike instanceof Error) {
|
|
2304
|
-
let isCompatibleInstance = check_error_exports.compatibleInstance(
|
|
2729
|
+
let isCompatibleInstance = check_error_exports.compatibleInstance(
|
|
2730
|
+
caughtErr,
|
|
2731
|
+
errorLike
|
|
2732
|
+
);
|
|
2305
2733
|
if (isCompatibleInstance === negate) {
|
|
2306
2734
|
if (everyArgIsDefined && negate) {
|
|
2307
2735
|
errorLikeFail = true;
|
|
2308
2736
|
} else {
|
|
2309
|
-
this.assert(
|
|
2737
|
+
this.assert(
|
|
2738
|
+
negate,
|
|
2739
|
+
"expected #{this} to throw #{exp} but #{act} was thrown",
|
|
2740
|
+
"expected #{this} to not throw #{exp}" + (caughtErr && !negate ? " but #{act} was thrown" : ""),
|
|
2741
|
+
errorLike.toString(),
|
|
2742
|
+
caughtErr.toString()
|
|
2743
|
+
);
|
|
2310
2744
|
}
|
|
2311
2745
|
}
|
|
2312
2746
|
}
|
|
2313
|
-
let isCompatibleConstructor = check_error_exports.compatibleConstructor(
|
|
2747
|
+
let isCompatibleConstructor = check_error_exports.compatibleConstructor(
|
|
2748
|
+
caughtErr,
|
|
2749
|
+
errorLike
|
|
2750
|
+
);
|
|
2314
2751
|
if (isCompatibleConstructor === negate) {
|
|
2315
2752
|
if (everyArgIsDefined && negate) {
|
|
2316
2753
|
errorLikeFail = true;
|
|
2317
2754
|
} else {
|
|
2318
|
-
this.assert(
|
|
2755
|
+
this.assert(
|
|
2756
|
+
negate,
|
|
2757
|
+
"expected #{this} to throw #{exp} but #{act} was thrown",
|
|
2758
|
+
"expected #{this} to not throw #{exp}" + (caughtErr ? " but #{act} was thrown" : ""),
|
|
2759
|
+
errorLike instanceof Error ? errorLike.toString() : errorLike && check_error_exports.getConstructorName(errorLike),
|
|
2760
|
+
caughtErr instanceof Error ? caughtErr.toString() : caughtErr && check_error_exports.getConstructorName(caughtErr)
|
|
2761
|
+
);
|
|
2319
2762
|
}
|
|
2320
2763
|
}
|
|
2321
2764
|
}
|
|
2322
|
-
if (caughtErr && errMsgMatcher !==
|
|
2765
|
+
if (caughtErr && errMsgMatcher !== void 0 && errMsgMatcher !== null) {
|
|
2323
2766
|
let placeholder = "including";
|
|
2324
2767
|
if (isRegExp2(errMsgMatcher)) {
|
|
2325
2768
|
placeholder = "matching";
|
|
2326
2769
|
}
|
|
2327
|
-
let isCompatibleMessage = check_error_exports.compatibleMessage(
|
|
2770
|
+
let isCompatibleMessage = check_error_exports.compatibleMessage(
|
|
2771
|
+
caughtErr,
|
|
2772
|
+
errMsgMatcher
|
|
2773
|
+
);
|
|
2328
2774
|
if (isCompatibleMessage === negate) {
|
|
2329
2775
|
if (everyArgIsDefined && negate) {
|
|
2330
2776
|
errMsgMatcherFail = true;
|
|
2331
2777
|
} else {
|
|
2332
|
-
this.assert(
|
|
2778
|
+
this.assert(
|
|
2779
|
+
negate,
|
|
2780
|
+
"expected #{this} to throw error " + placeholder + " #{exp} but got #{act}",
|
|
2781
|
+
"expected #{this} to throw error not " + placeholder + " #{exp}",
|
|
2782
|
+
errMsgMatcher,
|
|
2783
|
+
check_error_exports.getMessage(caughtErr)
|
|
2784
|
+
);
|
|
2333
2785
|
}
|
|
2334
2786
|
}
|
|
2335
2787
|
}
|
|
2336
2788
|
if (errorLikeFail && errMsgMatcherFail) {
|
|
2337
|
-
this.assert(
|
|
2789
|
+
this.assert(
|
|
2790
|
+
negate,
|
|
2791
|
+
"expected #{this} to throw #{exp} but #{act} was thrown",
|
|
2792
|
+
"expected #{this} to not throw #{exp}" + (caughtErr ? " but #{act} was thrown" : ""),
|
|
2793
|
+
errorLike instanceof Error ? errorLike.toString() : errorLike && check_error_exports.getConstructorName(errorLike),
|
|
2794
|
+
caughtErr instanceof Error ? caughtErr.toString() : caughtErr && check_error_exports.getConstructorName(caughtErr)
|
|
2795
|
+
);
|
|
2338
2796
|
}
|
|
2339
2797
|
flag2(this, "object", caughtErr);
|
|
2340
2798
|
}
|
|
@@ -2343,10 +2801,13 @@ Assertion.addMethod("throw", assertThrows);
|
|
|
2343
2801
|
Assertion.addMethod("throws", assertThrows);
|
|
2344
2802
|
Assertion.addMethod("Throw", assertThrows);
|
|
2345
2803
|
function respondTo(method, msg) {
|
|
2346
|
-
if (msg)
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2804
|
+
if (msg) flag2(this, "message", msg);
|
|
2805
|
+
let obj = flag2(this, "object"), itself = flag2(this, "itself"), context = "function" === typeof obj && !itself ? obj.prototype[method] : obj[method];
|
|
2806
|
+
this.assert(
|
|
2807
|
+
"function" === typeof context,
|
|
2808
|
+
"expected #{this} to respond to " + inspect2(method),
|
|
2809
|
+
"expected #{this} to not respond to " + inspect2(method)
|
|
2810
|
+
);
|
|
2350
2811
|
}
|
|
2351
2812
|
__name(respondTo, "respondTo");
|
|
2352
2813
|
Assertion.addMethod("respondTo", respondTo);
|
|
@@ -2355,33 +2816,49 @@ Assertion.addProperty("itself", function() {
|
|
|
2355
2816
|
flag2(this, "itself", true);
|
|
2356
2817
|
});
|
|
2357
2818
|
function satisfy(matcher, msg) {
|
|
2358
|
-
if (msg)
|
|
2359
|
-
flag2(this, "message", msg);
|
|
2819
|
+
if (msg) flag2(this, "message", msg);
|
|
2360
2820
|
let obj = flag2(this, "object");
|
|
2361
2821
|
let result = matcher(obj);
|
|
2362
|
-
this.assert(
|
|
2822
|
+
this.assert(
|
|
2823
|
+
result,
|
|
2824
|
+
"expected #{this} to satisfy " + objDisplay(matcher),
|
|
2825
|
+
"expected #{this} to not satisfy" + objDisplay(matcher),
|
|
2826
|
+
flag2(this, "negate") ? false : true,
|
|
2827
|
+
result
|
|
2828
|
+
);
|
|
2363
2829
|
}
|
|
2364
2830
|
__name(satisfy, "satisfy");
|
|
2365
2831
|
Assertion.addMethod("satisfy", satisfy);
|
|
2366
2832
|
Assertion.addMethod("satisfies", satisfy);
|
|
2367
2833
|
function closeTo(expected, delta, msg) {
|
|
2368
|
-
if (msg)
|
|
2369
|
-
flag2(this, "message", msg);
|
|
2834
|
+
if (msg) flag2(this, "message", msg);
|
|
2370
2835
|
let obj = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
2371
2836
|
new Assertion(obj, flagMsg, ssfi, true).is.numeric;
|
|
2372
2837
|
let message = "A `delta` value is required for `closeTo`";
|
|
2373
|
-
if (delta ==
|
|
2374
|
-
throw new AssertionError(
|
|
2838
|
+
if (delta == void 0) {
|
|
2839
|
+
throw new AssertionError(
|
|
2840
|
+
flagMsg ? `${flagMsg}: ${message}` : message,
|
|
2841
|
+
void 0,
|
|
2842
|
+
ssfi
|
|
2843
|
+
);
|
|
2375
2844
|
}
|
|
2376
2845
|
new Assertion(delta, flagMsg, ssfi, true).is.numeric;
|
|
2377
2846
|
message = "A `expected` value is required for `closeTo`";
|
|
2378
|
-
if (expected ==
|
|
2379
|
-
throw new AssertionError(
|
|
2847
|
+
if (expected == void 0) {
|
|
2848
|
+
throw new AssertionError(
|
|
2849
|
+
flagMsg ? `${flagMsg}: ${message}` : message,
|
|
2850
|
+
void 0,
|
|
2851
|
+
ssfi
|
|
2852
|
+
);
|
|
2380
2853
|
}
|
|
2381
2854
|
new Assertion(expected, flagMsg, ssfi, true).is.numeric;
|
|
2382
2855
|
const abs = /* @__PURE__ */ __name((x) => x < 0 ? -x : x, "abs");
|
|
2383
2856
|
const strip = /* @__PURE__ */ __name((number) => parseFloat(parseFloat(number).toPrecision(12)), "strip");
|
|
2384
|
-
this.assert(
|
|
2857
|
+
this.assert(
|
|
2858
|
+
strip(abs(obj - expected)) <= delta,
|
|
2859
|
+
"expected #{this} to be close to " + expected + " +/- " + delta,
|
|
2860
|
+
"expected #{this} not to be close to " + expected + " +/- " + delta
|
|
2861
|
+
);
|
|
2385
2862
|
}
|
|
2386
2863
|
__name(closeTo, "closeTo");
|
|
2387
2864
|
Assertion.addMethod("closeTo", closeTo);
|
|
@@ -2390,34 +2867,27 @@ function isSubsetOf(_subset, _superset, cmp, contains, ordered) {
|
|
|
2390
2867
|
let superset = Array.from(_superset);
|
|
2391
2868
|
let subset = Array.from(_subset);
|
|
2392
2869
|
if (!contains) {
|
|
2393
|
-
if (subset.length !== superset.length)
|
|
2394
|
-
return false;
|
|
2870
|
+
if (subset.length !== superset.length) return false;
|
|
2395
2871
|
superset = superset.slice();
|
|
2396
2872
|
}
|
|
2397
2873
|
return subset.every(function(elem, idx) {
|
|
2398
|
-
if (ordered)
|
|
2399
|
-
return cmp ? cmp(elem, superset[idx]) : elem === superset[idx];
|
|
2874
|
+
if (ordered) return cmp ? cmp(elem, superset[idx]) : elem === superset[idx];
|
|
2400
2875
|
if (!cmp) {
|
|
2401
2876
|
let matchIdx = superset.indexOf(elem);
|
|
2402
|
-
if (matchIdx === -1)
|
|
2403
|
-
|
|
2404
|
-
if (!contains)
|
|
2405
|
-
superset.splice(matchIdx, 1);
|
|
2877
|
+
if (matchIdx === -1) return false;
|
|
2878
|
+
if (!contains) superset.splice(matchIdx, 1);
|
|
2406
2879
|
return true;
|
|
2407
2880
|
}
|
|
2408
2881
|
return superset.some(function(elem2, matchIdx) {
|
|
2409
|
-
if (!cmp(elem, elem2))
|
|
2410
|
-
|
|
2411
|
-
if (!contains)
|
|
2412
|
-
superset.splice(matchIdx, 1);
|
|
2882
|
+
if (!cmp(elem, elem2)) return false;
|
|
2883
|
+
if (!contains) superset.splice(matchIdx, 1);
|
|
2413
2884
|
return true;
|
|
2414
2885
|
});
|
|
2415
2886
|
});
|
|
2416
2887
|
}
|
|
2417
2888
|
__name(isSubsetOf, "isSubsetOf");
|
|
2418
2889
|
Assertion.addMethod("members", function(subset, msg) {
|
|
2419
|
-
if (msg)
|
|
2420
|
-
flag2(this, "message", msg);
|
|
2890
|
+
if (msg) flag2(this, "message", msg);
|
|
2421
2891
|
let obj = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
2422
2892
|
new Assertion(obj, flagMsg, ssfi, true).to.be.iterable;
|
|
2423
2893
|
new Assertion(subset, flagMsg, ssfi, true).to.be.iterable;
|
|
@@ -2433,39 +2903,66 @@ Assertion.addMethod("members", function(subset, msg) {
|
|
|
2433
2903
|
failMsg = "expected #{this} to have the same " + subject + " as #{exp}";
|
|
2434
2904
|
failNegateMsg = "expected #{this} to not have the same " + subject + " as #{exp}";
|
|
2435
2905
|
}
|
|
2436
|
-
let cmp = flag2(this, "deep") ? flag2(this, "eql") :
|
|
2437
|
-
this.assert(
|
|
2906
|
+
let cmp = flag2(this, "deep") ? flag2(this, "eql") : void 0;
|
|
2907
|
+
this.assert(
|
|
2908
|
+
isSubsetOf(subset, obj, cmp, contains, ordered),
|
|
2909
|
+
failMsg,
|
|
2910
|
+
failNegateMsg,
|
|
2911
|
+
subset,
|
|
2912
|
+
obj,
|
|
2913
|
+
true
|
|
2914
|
+
);
|
|
2438
2915
|
});
|
|
2439
2916
|
Assertion.addProperty("iterable", function(msg) {
|
|
2440
|
-
if (msg)
|
|
2441
|
-
flag2(this, "message", msg);
|
|
2917
|
+
if (msg) flag2(this, "message", msg);
|
|
2442
2918
|
let obj = flag2(this, "object");
|
|
2443
|
-
this.assert(
|
|
2919
|
+
this.assert(
|
|
2920
|
+
obj != void 0 && obj[Symbol.iterator],
|
|
2921
|
+
"expected #{this} to be an iterable",
|
|
2922
|
+
"expected #{this} to not be an iterable",
|
|
2923
|
+
obj
|
|
2924
|
+
);
|
|
2444
2925
|
});
|
|
2445
2926
|
function oneOf(list, msg) {
|
|
2446
|
-
if (msg)
|
|
2447
|
-
flag2(this, "message", msg);
|
|
2927
|
+
if (msg) flag2(this, "message", msg);
|
|
2448
2928
|
let expected = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi"), contains = flag2(this, "contains"), isDeep = flag2(this, "deep"), eql = flag2(this, "eql");
|
|
2449
2929
|
new Assertion(list, flagMsg, ssfi, true).to.be.an("array");
|
|
2450
2930
|
if (contains) {
|
|
2451
|
-
this.assert(
|
|
2452
|
-
|
|
2453
|
-
|
|
2931
|
+
this.assert(
|
|
2932
|
+
list.some(function(possibility) {
|
|
2933
|
+
return expected.indexOf(possibility) > -1;
|
|
2934
|
+
}),
|
|
2935
|
+
"expected #{this} to contain one of #{exp}",
|
|
2936
|
+
"expected #{this} to not contain one of #{exp}",
|
|
2937
|
+
list,
|
|
2938
|
+
expected
|
|
2939
|
+
);
|
|
2454
2940
|
} else {
|
|
2455
2941
|
if (isDeep) {
|
|
2456
|
-
this.assert(
|
|
2457
|
-
|
|
2458
|
-
|
|
2942
|
+
this.assert(
|
|
2943
|
+
list.some(function(possibility) {
|
|
2944
|
+
return eql(expected, possibility);
|
|
2945
|
+
}),
|
|
2946
|
+
"expected #{this} to deeply equal one of #{exp}",
|
|
2947
|
+
"expected #{this} to deeply equal one of #{exp}",
|
|
2948
|
+
list,
|
|
2949
|
+
expected
|
|
2950
|
+
);
|
|
2459
2951
|
} else {
|
|
2460
|
-
this.assert(
|
|
2952
|
+
this.assert(
|
|
2953
|
+
list.indexOf(expected) > -1,
|
|
2954
|
+
"expected #{this} to be one of #{exp}",
|
|
2955
|
+
"expected #{this} to not be one of #{exp}",
|
|
2956
|
+
list,
|
|
2957
|
+
expected
|
|
2958
|
+
);
|
|
2461
2959
|
}
|
|
2462
2960
|
}
|
|
2463
2961
|
}
|
|
2464
2962
|
__name(oneOf, "oneOf");
|
|
2465
2963
|
Assertion.addMethod("oneOf", oneOf);
|
|
2466
2964
|
function assertChanges(subject, prop, msg) {
|
|
2467
|
-
if (msg)
|
|
2468
|
-
flag2(this, "message", msg);
|
|
2965
|
+
if (msg) flag2(this, "message", msg);
|
|
2469
2966
|
let fn = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
2470
2967
|
new Assertion(fn, flagMsg, ssfi, true).is.a("function");
|
|
2471
2968
|
let initial;
|
|
@@ -2477,21 +2974,24 @@ function assertChanges(subject, prop, msg) {
|
|
|
2477
2974
|
initial = subject[prop];
|
|
2478
2975
|
}
|
|
2479
2976
|
fn();
|
|
2480
|
-
let final = prop ===
|
|
2481
|
-
let msgObj = prop ===
|
|
2977
|
+
let final = prop === void 0 || prop === null ? subject() : subject[prop];
|
|
2978
|
+
let msgObj = prop === void 0 || prop === null ? initial : "." + prop;
|
|
2482
2979
|
flag2(this, "deltaMsgObj", msgObj);
|
|
2483
2980
|
flag2(this, "initialDeltaValue", initial);
|
|
2484
2981
|
flag2(this, "finalDeltaValue", final);
|
|
2485
2982
|
flag2(this, "deltaBehavior", "change");
|
|
2486
2983
|
flag2(this, "realDelta", final !== initial);
|
|
2487
|
-
this.assert(
|
|
2984
|
+
this.assert(
|
|
2985
|
+
initial !== final,
|
|
2986
|
+
"expected " + msgObj + " to change",
|
|
2987
|
+
"expected " + msgObj + " to not change"
|
|
2988
|
+
);
|
|
2488
2989
|
}
|
|
2489
2990
|
__name(assertChanges, "assertChanges");
|
|
2490
2991
|
Assertion.addMethod("change", assertChanges);
|
|
2491
2992
|
Assertion.addMethod("changes", assertChanges);
|
|
2492
2993
|
function assertIncreases(subject, prop, msg) {
|
|
2493
|
-
if (msg)
|
|
2494
|
-
flag2(this, "message", msg);
|
|
2994
|
+
if (msg) flag2(this, "message", msg);
|
|
2495
2995
|
let fn = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
2496
2996
|
new Assertion(fn, flagMsg, ssfi, true).is.a("function");
|
|
2497
2997
|
let initial;
|
|
@@ -2504,21 +3004,24 @@ function assertIncreases(subject, prop, msg) {
|
|
|
2504
3004
|
}
|
|
2505
3005
|
new Assertion(initial, flagMsg, ssfi, true).is.a("number");
|
|
2506
3006
|
fn();
|
|
2507
|
-
let final = prop ===
|
|
2508
|
-
let msgObj = prop ===
|
|
3007
|
+
let final = prop === void 0 || prop === null ? subject() : subject[prop];
|
|
3008
|
+
let msgObj = prop === void 0 || prop === null ? initial : "." + prop;
|
|
2509
3009
|
flag2(this, "deltaMsgObj", msgObj);
|
|
2510
3010
|
flag2(this, "initialDeltaValue", initial);
|
|
2511
3011
|
flag2(this, "finalDeltaValue", final);
|
|
2512
3012
|
flag2(this, "deltaBehavior", "increase");
|
|
2513
3013
|
flag2(this, "realDelta", final - initial);
|
|
2514
|
-
this.assert(
|
|
3014
|
+
this.assert(
|
|
3015
|
+
final - initial > 0,
|
|
3016
|
+
"expected " + msgObj + " to increase",
|
|
3017
|
+
"expected " + msgObj + " to not increase"
|
|
3018
|
+
);
|
|
2515
3019
|
}
|
|
2516
3020
|
__name(assertIncreases, "assertIncreases");
|
|
2517
3021
|
Assertion.addMethod("increase", assertIncreases);
|
|
2518
3022
|
Assertion.addMethod("increases", assertIncreases);
|
|
2519
3023
|
function assertDecreases(subject, prop, msg) {
|
|
2520
|
-
if (msg)
|
|
2521
|
-
flag2(this, "message", msg);
|
|
3024
|
+
if (msg) flag2(this, "message", msg);
|
|
2522
3025
|
let fn = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
2523
3026
|
new Assertion(fn, flagMsg, ssfi, true).is.a("function");
|
|
2524
3027
|
let initial;
|
|
@@ -2531,21 +3034,24 @@ function assertDecreases(subject, prop, msg) {
|
|
|
2531
3034
|
}
|
|
2532
3035
|
new Assertion(initial, flagMsg, ssfi, true).is.a("number");
|
|
2533
3036
|
fn();
|
|
2534
|
-
let final = prop ===
|
|
2535
|
-
let msgObj = prop ===
|
|
3037
|
+
let final = prop === void 0 || prop === null ? subject() : subject[prop];
|
|
3038
|
+
let msgObj = prop === void 0 || prop === null ? initial : "." + prop;
|
|
2536
3039
|
flag2(this, "deltaMsgObj", msgObj);
|
|
2537
3040
|
flag2(this, "initialDeltaValue", initial);
|
|
2538
3041
|
flag2(this, "finalDeltaValue", final);
|
|
2539
3042
|
flag2(this, "deltaBehavior", "decrease");
|
|
2540
3043
|
flag2(this, "realDelta", initial - final);
|
|
2541
|
-
this.assert(
|
|
3044
|
+
this.assert(
|
|
3045
|
+
final - initial < 0,
|
|
3046
|
+
"expected " + msgObj + " to decrease",
|
|
3047
|
+
"expected " + msgObj + " to not decrease"
|
|
3048
|
+
);
|
|
2542
3049
|
}
|
|
2543
3050
|
__name(assertDecreases, "assertDecreases");
|
|
2544
3051
|
Assertion.addMethod("decrease", assertDecreases);
|
|
2545
3052
|
Assertion.addMethod("decreases", assertDecreases);
|
|
2546
3053
|
function assertDelta(delta, msg) {
|
|
2547
|
-
if (msg)
|
|
2548
|
-
flag2(this, "message", msg);
|
|
3054
|
+
if (msg) flag2(this, "message", msg);
|
|
2549
3055
|
let msgObj = flag2(this, "deltaMsgObj");
|
|
2550
3056
|
let initial = flag2(this, "initialDeltaValue");
|
|
2551
3057
|
let final = flag2(this, "finalDeltaValue");
|
|
@@ -2557,28 +3063,48 @@ function assertDelta(delta, msg) {
|
|
|
2557
3063
|
} else {
|
|
2558
3064
|
expression = realDelta === Math.abs(delta);
|
|
2559
3065
|
}
|
|
2560
|
-
this.assert(
|
|
3066
|
+
this.assert(
|
|
3067
|
+
expression,
|
|
3068
|
+
"expected " + msgObj + " to " + behavior + " by " + delta,
|
|
3069
|
+
"expected " + msgObj + " to not " + behavior + " by " + delta
|
|
3070
|
+
);
|
|
2561
3071
|
}
|
|
2562
3072
|
__name(assertDelta, "assertDelta");
|
|
2563
3073
|
Assertion.addMethod("by", assertDelta);
|
|
2564
3074
|
Assertion.addProperty("extensible", function() {
|
|
2565
3075
|
let obj = flag2(this, "object");
|
|
2566
3076
|
let isExtensible = obj === Object(obj) && Object.isExtensible(obj);
|
|
2567
|
-
this.assert(
|
|
3077
|
+
this.assert(
|
|
3078
|
+
isExtensible,
|
|
3079
|
+
"expected #{this} to be extensible",
|
|
3080
|
+
"expected #{this} to not be extensible"
|
|
3081
|
+
);
|
|
2568
3082
|
});
|
|
2569
3083
|
Assertion.addProperty("sealed", function() {
|
|
2570
3084
|
let obj = flag2(this, "object");
|
|
2571
3085
|
let isSealed = obj === Object(obj) ? Object.isSealed(obj) : true;
|
|
2572
|
-
this.assert(
|
|
3086
|
+
this.assert(
|
|
3087
|
+
isSealed,
|
|
3088
|
+
"expected #{this} to be sealed",
|
|
3089
|
+
"expected #{this} to not be sealed"
|
|
3090
|
+
);
|
|
2573
3091
|
});
|
|
2574
3092
|
Assertion.addProperty("frozen", function() {
|
|
2575
3093
|
let obj = flag2(this, "object");
|
|
2576
3094
|
let isFrozen = obj === Object(obj) ? Object.isFrozen(obj) : true;
|
|
2577
|
-
this.assert(
|
|
3095
|
+
this.assert(
|
|
3096
|
+
isFrozen,
|
|
3097
|
+
"expected #{this} to be frozen",
|
|
3098
|
+
"expected #{this} to not be frozen"
|
|
3099
|
+
);
|
|
2578
3100
|
});
|
|
2579
3101
|
Assertion.addProperty("finite", function(_msg) {
|
|
2580
3102
|
let obj = flag2(this, "object");
|
|
2581
|
-
this.assert(
|
|
3103
|
+
this.assert(
|
|
3104
|
+
typeof obj === "number" && isFinite(obj),
|
|
3105
|
+
"expected #{this} to be a finite number",
|
|
3106
|
+
"expected #{this} to not be a finite number"
|
|
3107
|
+
);
|
|
2582
3108
|
});
|
|
2583
3109
|
function compareSubset(expected, actual) {
|
|
2584
3110
|
if (expected === actual) {
|
|
@@ -2626,7 +3152,14 @@ __name(compareSubset, "compareSubset");
|
|
|
2626
3152
|
Assertion.addMethod("containSubset", function(expected) {
|
|
2627
3153
|
const actual = flag(this, "object");
|
|
2628
3154
|
const showDiff = config.showDiff;
|
|
2629
|
-
this.assert(
|
|
3155
|
+
this.assert(
|
|
3156
|
+
compareSubset(expected, actual),
|
|
3157
|
+
"expected #{act} to contain subset #{exp}",
|
|
3158
|
+
"expected #{act} to not contain subset #{exp}",
|
|
3159
|
+
expected,
|
|
3160
|
+
actual,
|
|
3161
|
+
showDiff
|
|
3162
|
+
);
|
|
2630
3163
|
});
|
|
2631
3164
|
function expect(val, message) {
|
|
2632
3165
|
return new Assertion(val, message);
|
|
@@ -2635,14 +3168,18 @@ __name(expect, "expect");
|
|
|
2635
3168
|
expect.fail = function(actual, expected, message, operator) {
|
|
2636
3169
|
if (arguments.length < 2) {
|
|
2637
3170
|
message = actual;
|
|
2638
|
-
actual =
|
|
3171
|
+
actual = void 0;
|
|
2639
3172
|
}
|
|
2640
3173
|
message = message || "expect.fail()";
|
|
2641
|
-
throw new AssertionError(
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
3174
|
+
throw new AssertionError(
|
|
3175
|
+
message,
|
|
3176
|
+
{
|
|
3177
|
+
actual,
|
|
3178
|
+
expected,
|
|
3179
|
+
operator
|
|
3180
|
+
},
|
|
3181
|
+
expect.fail
|
|
3182
|
+
);
|
|
2646
3183
|
};
|
|
2647
3184
|
var should_exports = {};
|
|
2648
3185
|
__export(should_exports, {
|
|
@@ -2675,14 +3212,18 @@ function loadShould() {
|
|
|
2675
3212
|
should2.fail = function(actual, expected, message, operator) {
|
|
2676
3213
|
if (arguments.length < 2) {
|
|
2677
3214
|
message = actual;
|
|
2678
|
-
actual =
|
|
3215
|
+
actual = void 0;
|
|
2679
3216
|
}
|
|
2680
3217
|
message = message || "should.fail()";
|
|
2681
|
-
throw new AssertionError(
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
3218
|
+
throw new AssertionError(
|
|
3219
|
+
message,
|
|
3220
|
+
{
|
|
3221
|
+
actual,
|
|
3222
|
+
expected,
|
|
3223
|
+
operator
|
|
3224
|
+
},
|
|
3225
|
+
should2.fail
|
|
3226
|
+
);
|
|
2686
3227
|
};
|
|
2687
3228
|
should2.equal = function(actual, expected, message) {
|
|
2688
3229
|
new Assertion(actual, message).to.equal(expected);
|
|
@@ -2718,14 +3259,18 @@ __name(assert, "assert");
|
|
|
2718
3259
|
assert.fail = function(actual, expected, message, operator) {
|
|
2719
3260
|
if (arguments.length < 2) {
|
|
2720
3261
|
message = actual;
|
|
2721
|
-
actual =
|
|
3262
|
+
actual = void 0;
|
|
2722
3263
|
}
|
|
2723
3264
|
message = message || "assert.fail()";
|
|
2724
|
-
throw new AssertionError(
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
3265
|
+
throw new AssertionError(
|
|
3266
|
+
message,
|
|
3267
|
+
{
|
|
3268
|
+
actual,
|
|
3269
|
+
expected,
|
|
3270
|
+
operator
|
|
3271
|
+
},
|
|
3272
|
+
assert.fail
|
|
3273
|
+
);
|
|
2729
3274
|
};
|
|
2730
3275
|
assert.isOk = function(val, msg) {
|
|
2731
3276
|
new Assertion(val, msg, assert.isOk, true).is.ok;
|
|
@@ -2735,11 +3280,25 @@ assert.isNotOk = function(val, msg) {
|
|
|
2735
3280
|
};
|
|
2736
3281
|
assert.equal = function(act, exp, msg) {
|
|
2737
3282
|
let test2 = new Assertion(act, msg, assert.equal, true);
|
|
2738
|
-
test2.assert(
|
|
3283
|
+
test2.assert(
|
|
3284
|
+
exp == flag(test2, "object"),
|
|
3285
|
+
"expected #{this} to equal #{exp}",
|
|
3286
|
+
"expected #{this} to not equal #{act}",
|
|
3287
|
+
exp,
|
|
3288
|
+
act,
|
|
3289
|
+
true
|
|
3290
|
+
);
|
|
2739
3291
|
};
|
|
2740
3292
|
assert.notEqual = function(act, exp, msg) {
|
|
2741
3293
|
let test2 = new Assertion(act, msg, assert.notEqual, true);
|
|
2742
|
-
test2.assert(
|
|
3294
|
+
test2.assert(
|
|
3295
|
+
exp != flag(test2, "object"),
|
|
3296
|
+
"expected #{this} to not equal #{exp}",
|
|
3297
|
+
"expected #{this} to equal #{act}",
|
|
3298
|
+
exp,
|
|
3299
|
+
act,
|
|
3300
|
+
true
|
|
3301
|
+
);
|
|
2743
3302
|
};
|
|
2744
3303
|
assert.strictEqual = function(act, exp, msg) {
|
|
2745
3304
|
new Assertion(act, msg, assert.strictEqual, true).to.equal(exp);
|
|
@@ -2796,10 +3355,10 @@ assert.notExists = function(val, msg) {
|
|
|
2796
3355
|
new Assertion(val, msg, assert.notExists, true).to.not.exist;
|
|
2797
3356
|
};
|
|
2798
3357
|
assert.isUndefined = function(val, msg) {
|
|
2799
|
-
new Assertion(val, msg, assert.isUndefined, true).to.equal(
|
|
3358
|
+
new Assertion(val, msg, assert.isUndefined, true).to.equal(void 0);
|
|
2800
3359
|
};
|
|
2801
3360
|
assert.isDefined = function(val, msg) {
|
|
2802
|
-
new Assertion(val, msg, assert.isDefined, true).to.not.equal(
|
|
3361
|
+
new Assertion(val, msg, assert.isDefined, true).to.not.equal(void 0);
|
|
2803
3362
|
};
|
|
2804
3363
|
assert.isCallable = function(value, message) {
|
|
2805
3364
|
new Assertion(value, message, assert.isCallable, true).is.callable;
|
|
@@ -2856,7 +3415,9 @@ assert.instanceOf = function(val, type3, msg) {
|
|
|
2856
3415
|
new Assertion(val, msg, assert.instanceOf, true).to.be.instanceOf(type3);
|
|
2857
3416
|
};
|
|
2858
3417
|
assert.notInstanceOf = function(val, type3, msg) {
|
|
2859
|
-
new Assertion(val, msg, assert.notInstanceOf, true).to.not.be.instanceOf(
|
|
3418
|
+
new Assertion(val, msg, assert.notInstanceOf, true).to.not.be.instanceOf(
|
|
3419
|
+
type3
|
|
3420
|
+
);
|
|
2860
3421
|
};
|
|
2861
3422
|
assert.include = function(exp, inc, msg) {
|
|
2862
3423
|
new Assertion(exp, msg, assert.include, true).include(inc);
|
|
@@ -2874,13 +3435,22 @@ assert.nestedInclude = function(exp, inc, msg) {
|
|
|
2874
3435
|
new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc);
|
|
2875
3436
|
};
|
|
2876
3437
|
assert.notNestedInclude = function(exp, inc, msg) {
|
|
2877
|
-
new Assertion(exp, msg, assert.notNestedInclude, true).not.nested.include(
|
|
3438
|
+
new Assertion(exp, msg, assert.notNestedInclude, true).not.nested.include(
|
|
3439
|
+
inc
|
|
3440
|
+
);
|
|
2878
3441
|
};
|
|
2879
3442
|
assert.deepNestedInclude = function(exp, inc, msg) {
|
|
2880
|
-
new Assertion(exp, msg, assert.deepNestedInclude, true).deep.nested.include(
|
|
3443
|
+
new Assertion(exp, msg, assert.deepNestedInclude, true).deep.nested.include(
|
|
3444
|
+
inc
|
|
3445
|
+
);
|
|
2881
3446
|
};
|
|
2882
3447
|
assert.notDeepNestedInclude = function(exp, inc, msg) {
|
|
2883
|
-
new Assertion(
|
|
3448
|
+
new Assertion(
|
|
3449
|
+
exp,
|
|
3450
|
+
msg,
|
|
3451
|
+
assert.notDeepNestedInclude,
|
|
3452
|
+
true
|
|
3453
|
+
).not.deep.nested.include(inc);
|
|
2884
3454
|
};
|
|
2885
3455
|
assert.ownInclude = function(exp, inc, msg) {
|
|
2886
3456
|
new Assertion(exp, msg, assert.ownInclude, true).own.include(inc);
|
|
@@ -2892,7 +3462,9 @@ assert.deepOwnInclude = function(exp, inc, msg) {
|
|
|
2892
3462
|
new Assertion(exp, msg, assert.deepOwnInclude, true).deep.own.include(inc);
|
|
2893
3463
|
};
|
|
2894
3464
|
assert.notDeepOwnInclude = function(exp, inc, msg) {
|
|
2895
|
-
new Assertion(exp, msg, assert.notDeepOwnInclude, true).not.deep.own.include(
|
|
3465
|
+
new Assertion(exp, msg, assert.notDeepOwnInclude, true).not.deep.own.include(
|
|
3466
|
+
inc
|
|
3467
|
+
);
|
|
2896
3468
|
};
|
|
2897
3469
|
assert.match = function(exp, re, msg) {
|
|
2898
3470
|
new Assertion(exp, msg, assert.match, true).to.match(re);
|
|
@@ -2910,49 +3482,107 @@ assert.propertyVal = function(obj, prop, val, msg) {
|
|
|
2910
3482
|
new Assertion(obj, msg, assert.propertyVal, true).to.have.property(prop, val);
|
|
2911
3483
|
};
|
|
2912
3484
|
assert.notPropertyVal = function(obj, prop, val, msg) {
|
|
2913
|
-
new Assertion(obj, msg, assert.notPropertyVal, true).to.not.have.property(
|
|
3485
|
+
new Assertion(obj, msg, assert.notPropertyVal, true).to.not.have.property(
|
|
3486
|
+
prop,
|
|
3487
|
+
val
|
|
3488
|
+
);
|
|
2914
3489
|
};
|
|
2915
3490
|
assert.deepPropertyVal = function(obj, prop, val, msg) {
|
|
2916
|
-
new Assertion(obj, msg, assert.deepPropertyVal, true).to.have.deep.property(
|
|
3491
|
+
new Assertion(obj, msg, assert.deepPropertyVal, true).to.have.deep.property(
|
|
3492
|
+
prop,
|
|
3493
|
+
val
|
|
3494
|
+
);
|
|
2917
3495
|
};
|
|
2918
3496
|
assert.notDeepPropertyVal = function(obj, prop, val, msg) {
|
|
2919
|
-
new Assertion(
|
|
3497
|
+
new Assertion(
|
|
3498
|
+
obj,
|
|
3499
|
+
msg,
|
|
3500
|
+
assert.notDeepPropertyVal,
|
|
3501
|
+
true
|
|
3502
|
+
).to.not.have.deep.property(prop, val);
|
|
2920
3503
|
};
|
|
2921
3504
|
assert.ownProperty = function(obj, prop, msg) {
|
|
2922
3505
|
new Assertion(obj, msg, assert.ownProperty, true).to.have.own.property(prop);
|
|
2923
3506
|
};
|
|
2924
3507
|
assert.notOwnProperty = function(obj, prop, msg) {
|
|
2925
|
-
new Assertion(obj, msg, assert.notOwnProperty, true).to.not.have.own.property(
|
|
3508
|
+
new Assertion(obj, msg, assert.notOwnProperty, true).to.not.have.own.property(
|
|
3509
|
+
prop
|
|
3510
|
+
);
|
|
2926
3511
|
};
|
|
2927
3512
|
assert.ownPropertyVal = function(obj, prop, value, msg) {
|
|
2928
|
-
new Assertion(obj, msg, assert.ownPropertyVal, true).to.have.own.property(
|
|
3513
|
+
new Assertion(obj, msg, assert.ownPropertyVal, true).to.have.own.property(
|
|
3514
|
+
prop,
|
|
3515
|
+
value
|
|
3516
|
+
);
|
|
2929
3517
|
};
|
|
2930
3518
|
assert.notOwnPropertyVal = function(obj, prop, value, msg) {
|
|
2931
|
-
new Assertion(
|
|
3519
|
+
new Assertion(
|
|
3520
|
+
obj,
|
|
3521
|
+
msg,
|
|
3522
|
+
assert.notOwnPropertyVal,
|
|
3523
|
+
true
|
|
3524
|
+
).to.not.have.own.property(prop, value);
|
|
2932
3525
|
};
|
|
2933
3526
|
assert.deepOwnPropertyVal = function(obj, prop, value, msg) {
|
|
2934
|
-
new Assertion(
|
|
3527
|
+
new Assertion(
|
|
3528
|
+
obj,
|
|
3529
|
+
msg,
|
|
3530
|
+
assert.deepOwnPropertyVal,
|
|
3531
|
+
true
|
|
3532
|
+
).to.have.deep.own.property(prop, value);
|
|
2935
3533
|
};
|
|
2936
3534
|
assert.notDeepOwnPropertyVal = function(obj, prop, value, msg) {
|
|
2937
|
-
new Assertion(
|
|
3535
|
+
new Assertion(
|
|
3536
|
+
obj,
|
|
3537
|
+
msg,
|
|
3538
|
+
assert.notDeepOwnPropertyVal,
|
|
3539
|
+
true
|
|
3540
|
+
).to.not.have.deep.own.property(prop, value);
|
|
2938
3541
|
};
|
|
2939
3542
|
assert.nestedProperty = function(obj, prop, msg) {
|
|
2940
|
-
new Assertion(obj, msg, assert.nestedProperty, true).to.have.nested.property(
|
|
3543
|
+
new Assertion(obj, msg, assert.nestedProperty, true).to.have.nested.property(
|
|
3544
|
+
prop
|
|
3545
|
+
);
|
|
2941
3546
|
};
|
|
2942
3547
|
assert.notNestedProperty = function(obj, prop, msg) {
|
|
2943
|
-
new Assertion(
|
|
3548
|
+
new Assertion(
|
|
3549
|
+
obj,
|
|
3550
|
+
msg,
|
|
3551
|
+
assert.notNestedProperty,
|
|
3552
|
+
true
|
|
3553
|
+
).to.not.have.nested.property(prop);
|
|
2944
3554
|
};
|
|
2945
3555
|
assert.nestedPropertyVal = function(obj, prop, val, msg) {
|
|
2946
|
-
new Assertion(
|
|
3556
|
+
new Assertion(
|
|
3557
|
+
obj,
|
|
3558
|
+
msg,
|
|
3559
|
+
assert.nestedPropertyVal,
|
|
3560
|
+
true
|
|
3561
|
+
).to.have.nested.property(prop, val);
|
|
2947
3562
|
};
|
|
2948
3563
|
assert.notNestedPropertyVal = function(obj, prop, val, msg) {
|
|
2949
|
-
new Assertion(
|
|
3564
|
+
new Assertion(
|
|
3565
|
+
obj,
|
|
3566
|
+
msg,
|
|
3567
|
+
assert.notNestedPropertyVal,
|
|
3568
|
+
true
|
|
3569
|
+
).to.not.have.nested.property(prop, val);
|
|
2950
3570
|
};
|
|
2951
3571
|
assert.deepNestedPropertyVal = function(obj, prop, val, msg) {
|
|
2952
|
-
new Assertion(
|
|
3572
|
+
new Assertion(
|
|
3573
|
+
obj,
|
|
3574
|
+
msg,
|
|
3575
|
+
assert.deepNestedPropertyVal,
|
|
3576
|
+
true
|
|
3577
|
+
).to.have.deep.nested.property(prop, val);
|
|
2953
3578
|
};
|
|
2954
3579
|
assert.notDeepNestedPropertyVal = function(obj, prop, val, msg) {
|
|
2955
|
-
new Assertion(
|
|
3580
|
+
new Assertion(
|
|
3581
|
+
obj,
|
|
3582
|
+
msg,
|
|
3583
|
+
assert.notDeepNestedPropertyVal,
|
|
3584
|
+
true
|
|
3585
|
+
).to.not.have.deep.nested.property(prop, val);
|
|
2956
3586
|
};
|
|
2957
3587
|
assert.lengthOf = function(exp, len, msg) {
|
|
2958
3588
|
new Assertion(exp, msg, assert.lengthOf, true).to.have.lengthOf(len);
|
|
@@ -2964,43 +3594,74 @@ assert.hasAllKeys = function(obj, keys, msg) {
|
|
|
2964
3594
|
new Assertion(obj, msg, assert.hasAllKeys, true).to.have.all.keys(keys);
|
|
2965
3595
|
};
|
|
2966
3596
|
assert.containsAllKeys = function(obj, keys, msg) {
|
|
2967
|
-
new Assertion(obj, msg, assert.containsAllKeys, true).to.contain.all.keys(
|
|
3597
|
+
new Assertion(obj, msg, assert.containsAllKeys, true).to.contain.all.keys(
|
|
3598
|
+
keys
|
|
3599
|
+
);
|
|
2968
3600
|
};
|
|
2969
3601
|
assert.doesNotHaveAnyKeys = function(obj, keys, msg) {
|
|
2970
|
-
new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true).to.not.have.any.keys(
|
|
3602
|
+
new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true).to.not.have.any.keys(
|
|
3603
|
+
keys
|
|
3604
|
+
);
|
|
2971
3605
|
};
|
|
2972
3606
|
assert.doesNotHaveAllKeys = function(obj, keys, msg) {
|
|
2973
|
-
new Assertion(obj, msg, assert.doesNotHaveAllKeys, true).to.not.have.all.keys(
|
|
3607
|
+
new Assertion(obj, msg, assert.doesNotHaveAllKeys, true).to.not.have.all.keys(
|
|
3608
|
+
keys
|
|
3609
|
+
);
|
|
2974
3610
|
};
|
|
2975
3611
|
assert.hasAnyDeepKeys = function(obj, keys, msg) {
|
|
2976
|
-
new Assertion(obj, msg, assert.hasAnyDeepKeys, true).to.have.any.deep.keys(
|
|
3612
|
+
new Assertion(obj, msg, assert.hasAnyDeepKeys, true).to.have.any.deep.keys(
|
|
3613
|
+
keys
|
|
3614
|
+
);
|
|
2977
3615
|
};
|
|
2978
3616
|
assert.hasAllDeepKeys = function(obj, keys, msg) {
|
|
2979
|
-
new Assertion(obj, msg, assert.hasAllDeepKeys, true).to.have.all.deep.keys(
|
|
3617
|
+
new Assertion(obj, msg, assert.hasAllDeepKeys, true).to.have.all.deep.keys(
|
|
3618
|
+
keys
|
|
3619
|
+
);
|
|
2980
3620
|
};
|
|
2981
3621
|
assert.containsAllDeepKeys = function(obj, keys, msg) {
|
|
2982
|
-
new Assertion(
|
|
3622
|
+
new Assertion(
|
|
3623
|
+
obj,
|
|
3624
|
+
msg,
|
|
3625
|
+
assert.containsAllDeepKeys,
|
|
3626
|
+
true
|
|
3627
|
+
).to.contain.all.deep.keys(keys);
|
|
2983
3628
|
};
|
|
2984
3629
|
assert.doesNotHaveAnyDeepKeys = function(obj, keys, msg) {
|
|
2985
|
-
new Assertion(
|
|
3630
|
+
new Assertion(
|
|
3631
|
+
obj,
|
|
3632
|
+
msg,
|
|
3633
|
+
assert.doesNotHaveAnyDeepKeys,
|
|
3634
|
+
true
|
|
3635
|
+
).to.not.have.any.deep.keys(keys);
|
|
2986
3636
|
};
|
|
2987
3637
|
assert.doesNotHaveAllDeepKeys = function(obj, keys, msg) {
|
|
2988
|
-
new Assertion(
|
|
3638
|
+
new Assertion(
|
|
3639
|
+
obj,
|
|
3640
|
+
msg,
|
|
3641
|
+
assert.doesNotHaveAllDeepKeys,
|
|
3642
|
+
true
|
|
3643
|
+
).to.not.have.all.deep.keys(keys);
|
|
2989
3644
|
};
|
|
2990
3645
|
assert.throws = function(fn, errorLike, errMsgMatcher, msg) {
|
|
2991
|
-
if (typeof errorLike
|
|
3646
|
+
if ("string" === typeof errorLike || errorLike instanceof RegExp) {
|
|
2992
3647
|
errMsgMatcher = errorLike;
|
|
2993
3648
|
errorLike = null;
|
|
2994
3649
|
}
|
|
2995
|
-
let assertErr = new Assertion(fn, msg, assert.throws, true).to.throw(
|
|
3650
|
+
let assertErr = new Assertion(fn, msg, assert.throws, true).to.throw(
|
|
3651
|
+
errorLike,
|
|
3652
|
+
errMsgMatcher
|
|
3653
|
+
);
|
|
2996
3654
|
return flag(assertErr, "object");
|
|
2997
3655
|
};
|
|
2998
3656
|
assert.doesNotThrow = function(fn, errorLike, errMsgMatcher, message) {
|
|
2999
|
-
if (typeof errorLike
|
|
3657
|
+
if ("string" === typeof errorLike || errorLike instanceof RegExp) {
|
|
3000
3658
|
errMsgMatcher = errorLike;
|
|
3001
3659
|
errorLike = null;
|
|
3002
3660
|
}
|
|
3003
|
-
new Assertion(fn, message, assert.doesNotThrow, true).to.not.throw(
|
|
3661
|
+
new Assertion(fn, message, assert.doesNotThrow, true).to.not.throw(
|
|
3662
|
+
errorLike,
|
|
3663
|
+
errMsgMatcher
|
|
3664
|
+
);
|
|
3004
3665
|
};
|
|
3005
3666
|
assert.operator = function(val, operator, val2, msg) {
|
|
3006
3667
|
let ok;
|
|
@@ -3031,72 +3692,155 @@ assert.operator = function(val, operator, val2, msg) {
|
|
|
3031
3692
|
break;
|
|
3032
3693
|
default:
|
|
3033
3694
|
msg = msg ? msg + ": " : msg;
|
|
3034
|
-
throw new AssertionError(
|
|
3695
|
+
throw new AssertionError(
|
|
3696
|
+
msg + 'Invalid operator "' + operator + '"',
|
|
3697
|
+
void 0,
|
|
3698
|
+
assert.operator
|
|
3699
|
+
);
|
|
3035
3700
|
}
|
|
3036
3701
|
let test2 = new Assertion(ok, msg, assert.operator, true);
|
|
3037
|
-
test2.assert(
|
|
3702
|
+
test2.assert(
|
|
3703
|
+
true === flag(test2, "object"),
|
|
3704
|
+
"expected " + inspect2(val) + " to be " + operator + " " + inspect2(val2),
|
|
3705
|
+
"expected " + inspect2(val) + " to not be " + operator + " " + inspect2(val2)
|
|
3706
|
+
);
|
|
3038
3707
|
};
|
|
3039
3708
|
assert.closeTo = function(act, exp, delta, msg) {
|
|
3040
3709
|
new Assertion(act, msg, assert.closeTo, true).to.be.closeTo(exp, delta);
|
|
3041
3710
|
};
|
|
3042
3711
|
assert.approximately = function(act, exp, delta, msg) {
|
|
3043
|
-
new Assertion(act, msg, assert.approximately, true).to.be.approximately(
|
|
3712
|
+
new Assertion(act, msg, assert.approximately, true).to.be.approximately(
|
|
3713
|
+
exp,
|
|
3714
|
+
delta
|
|
3715
|
+
);
|
|
3044
3716
|
};
|
|
3045
3717
|
assert.sameMembers = function(set1, set2, msg) {
|
|
3046
3718
|
new Assertion(set1, msg, assert.sameMembers, true).to.have.same.members(set2);
|
|
3047
3719
|
};
|
|
3048
3720
|
assert.notSameMembers = function(set1, set2, msg) {
|
|
3049
|
-
new Assertion(
|
|
3721
|
+
new Assertion(
|
|
3722
|
+
set1,
|
|
3723
|
+
msg,
|
|
3724
|
+
assert.notSameMembers,
|
|
3725
|
+
true
|
|
3726
|
+
).to.not.have.same.members(set2);
|
|
3050
3727
|
};
|
|
3051
3728
|
assert.sameDeepMembers = function(set1, set2, msg) {
|
|
3052
|
-
new Assertion(
|
|
3729
|
+
new Assertion(
|
|
3730
|
+
set1,
|
|
3731
|
+
msg,
|
|
3732
|
+
assert.sameDeepMembers,
|
|
3733
|
+
true
|
|
3734
|
+
).to.have.same.deep.members(set2);
|
|
3053
3735
|
};
|
|
3054
3736
|
assert.notSameDeepMembers = function(set1, set2, msg) {
|
|
3055
|
-
new Assertion(
|
|
3737
|
+
new Assertion(
|
|
3738
|
+
set1,
|
|
3739
|
+
msg,
|
|
3740
|
+
assert.notSameDeepMembers,
|
|
3741
|
+
true
|
|
3742
|
+
).to.not.have.same.deep.members(set2);
|
|
3056
3743
|
};
|
|
3057
3744
|
assert.sameOrderedMembers = function(set1, set2, msg) {
|
|
3058
|
-
new Assertion(
|
|
3745
|
+
new Assertion(
|
|
3746
|
+
set1,
|
|
3747
|
+
msg,
|
|
3748
|
+
assert.sameOrderedMembers,
|
|
3749
|
+
true
|
|
3750
|
+
).to.have.same.ordered.members(set2);
|
|
3059
3751
|
};
|
|
3060
3752
|
assert.notSameOrderedMembers = function(set1, set2, msg) {
|
|
3061
|
-
new Assertion(
|
|
3753
|
+
new Assertion(
|
|
3754
|
+
set1,
|
|
3755
|
+
msg,
|
|
3756
|
+
assert.notSameOrderedMembers,
|
|
3757
|
+
true
|
|
3758
|
+
).to.not.have.same.ordered.members(set2);
|
|
3062
3759
|
};
|
|
3063
3760
|
assert.sameDeepOrderedMembers = function(set1, set2, msg) {
|
|
3064
|
-
new Assertion(
|
|
3761
|
+
new Assertion(
|
|
3762
|
+
set1,
|
|
3763
|
+
msg,
|
|
3764
|
+
assert.sameDeepOrderedMembers,
|
|
3765
|
+
true
|
|
3766
|
+
).to.have.same.deep.ordered.members(set2);
|
|
3065
3767
|
};
|
|
3066
3768
|
assert.notSameDeepOrderedMembers = function(set1, set2, msg) {
|
|
3067
|
-
new Assertion(
|
|
3769
|
+
new Assertion(
|
|
3770
|
+
set1,
|
|
3771
|
+
msg,
|
|
3772
|
+
assert.notSameDeepOrderedMembers,
|
|
3773
|
+
true
|
|
3774
|
+
).to.not.have.same.deep.ordered.members(set2);
|
|
3068
3775
|
};
|
|
3069
3776
|
assert.includeMembers = function(superset, subset, msg) {
|
|
3070
|
-
new Assertion(superset, msg, assert.includeMembers, true).to.include.members(
|
|
3777
|
+
new Assertion(superset, msg, assert.includeMembers, true).to.include.members(
|
|
3778
|
+
subset
|
|
3779
|
+
);
|
|
3071
3780
|
};
|
|
3072
3781
|
assert.notIncludeMembers = function(superset, subset, msg) {
|
|
3073
|
-
new Assertion(
|
|
3782
|
+
new Assertion(
|
|
3783
|
+
superset,
|
|
3784
|
+
msg,
|
|
3785
|
+
assert.notIncludeMembers,
|
|
3786
|
+
true
|
|
3787
|
+
).to.not.include.members(subset);
|
|
3074
3788
|
};
|
|
3075
3789
|
assert.includeDeepMembers = function(superset, subset, msg) {
|
|
3076
|
-
new Assertion(
|
|
3790
|
+
new Assertion(
|
|
3791
|
+
superset,
|
|
3792
|
+
msg,
|
|
3793
|
+
assert.includeDeepMembers,
|
|
3794
|
+
true
|
|
3795
|
+
).to.include.deep.members(subset);
|
|
3077
3796
|
};
|
|
3078
3797
|
assert.notIncludeDeepMembers = function(superset, subset, msg) {
|
|
3079
|
-
new Assertion(
|
|
3798
|
+
new Assertion(
|
|
3799
|
+
superset,
|
|
3800
|
+
msg,
|
|
3801
|
+
assert.notIncludeDeepMembers,
|
|
3802
|
+
true
|
|
3803
|
+
).to.not.include.deep.members(subset);
|
|
3080
3804
|
};
|
|
3081
3805
|
assert.includeOrderedMembers = function(superset, subset, msg) {
|
|
3082
|
-
new Assertion(
|
|
3806
|
+
new Assertion(
|
|
3807
|
+
superset,
|
|
3808
|
+
msg,
|
|
3809
|
+
assert.includeOrderedMembers,
|
|
3810
|
+
true
|
|
3811
|
+
).to.include.ordered.members(subset);
|
|
3083
3812
|
};
|
|
3084
3813
|
assert.notIncludeOrderedMembers = function(superset, subset, msg) {
|
|
3085
|
-
new Assertion(
|
|
3814
|
+
new Assertion(
|
|
3815
|
+
superset,
|
|
3816
|
+
msg,
|
|
3817
|
+
assert.notIncludeOrderedMembers,
|
|
3818
|
+
true
|
|
3819
|
+
).to.not.include.ordered.members(subset);
|
|
3086
3820
|
};
|
|
3087
3821
|
assert.includeDeepOrderedMembers = function(superset, subset, msg) {
|
|
3088
|
-
new Assertion(
|
|
3822
|
+
new Assertion(
|
|
3823
|
+
superset,
|
|
3824
|
+
msg,
|
|
3825
|
+
assert.includeDeepOrderedMembers,
|
|
3826
|
+
true
|
|
3827
|
+
).to.include.deep.ordered.members(subset);
|
|
3089
3828
|
};
|
|
3090
3829
|
assert.notIncludeDeepOrderedMembers = function(superset, subset, msg) {
|
|
3091
|
-
new Assertion(
|
|
3830
|
+
new Assertion(
|
|
3831
|
+
superset,
|
|
3832
|
+
msg,
|
|
3833
|
+
assert.notIncludeDeepOrderedMembers,
|
|
3834
|
+
true
|
|
3835
|
+
).to.not.include.deep.ordered.members(subset);
|
|
3092
3836
|
};
|
|
3093
3837
|
assert.oneOf = function(inList, list, msg) {
|
|
3094
3838
|
new Assertion(inList, msg, assert.oneOf, true).to.be.oneOf(list);
|
|
3095
3839
|
};
|
|
3096
3840
|
assert.isIterable = function(obj, msg) {
|
|
3097
|
-
if (obj ==
|
|
3841
|
+
if (obj == void 0 || !obj[Symbol.iterator]) {
|
|
3098
3842
|
msg = msg ? `${msg} expected ${inspect2(obj)} to be an iterable` : `expected ${inspect2(obj)} to be an iterable`;
|
|
3099
|
-
throw new AssertionError(msg,
|
|
3843
|
+
throw new AssertionError(msg, void 0, assert.isIterable);
|
|
3100
3844
|
}
|
|
3101
3845
|
};
|
|
3102
3846
|
assert.changes = function(fn, obj, prop, msg) {
|
|
@@ -3122,7 +3866,10 @@ assert.doesNotChange = function(fn, obj, prop, msg) {
|
|
|
3122
3866
|
msg = prop;
|
|
3123
3867
|
prop = null;
|
|
3124
3868
|
}
|
|
3125
|
-
return new Assertion(fn, msg, assert.doesNotChange, true).to.not.change(
|
|
3869
|
+
return new Assertion(fn, msg, assert.doesNotChange, true).to.not.change(
|
|
3870
|
+
obj,
|
|
3871
|
+
prop
|
|
3872
|
+
);
|
|
3126
3873
|
};
|
|
3127
3874
|
assert.changesButNotBy = function(fn, obj, prop, delta, msg) {
|
|
3128
3875
|
if (arguments.length === 4 && typeof obj === "function") {
|
|
@@ -3158,7 +3905,10 @@ assert.doesNotIncrease = function(fn, obj, prop, msg) {
|
|
|
3158
3905
|
msg = prop;
|
|
3159
3906
|
prop = null;
|
|
3160
3907
|
}
|
|
3161
|
-
return new Assertion(fn, msg, assert.doesNotIncrease, true).to.not.increase(
|
|
3908
|
+
return new Assertion(fn, msg, assert.doesNotIncrease, true).to.not.increase(
|
|
3909
|
+
obj,
|
|
3910
|
+
prop
|
|
3911
|
+
);
|
|
3162
3912
|
};
|
|
3163
3913
|
assert.increasesButNotBy = function(fn, obj, prop, delta, msg) {
|
|
3164
3914
|
if (arguments.length === 4 && typeof obj === "function") {
|
|
@@ -3194,7 +3944,10 @@ assert.doesNotDecrease = function(fn, obj, prop, msg) {
|
|
|
3194
3944
|
msg = prop;
|
|
3195
3945
|
prop = null;
|
|
3196
3946
|
}
|
|
3197
|
-
return new Assertion(fn, msg, assert.doesNotDecrease, true).to.not.decrease(
|
|
3947
|
+
return new Assertion(fn, msg, assert.doesNotDecrease, true).to.not.decrease(
|
|
3948
|
+
obj,
|
|
3949
|
+
prop
|
|
3950
|
+
);
|
|
3198
3951
|
};
|
|
3199
3952
|
assert.doesNotDecreaseBy = function(fn, obj, prop, delta, msg) {
|
|
3200
3953
|
if (arguments.length === 4 && typeof obj === "function") {
|
|
@@ -3298,31 +4051,69 @@ function jestMatchers(chai, utils) {
|
|
|
3298
4051
|
const A = chai.Assertion;
|
|
3299
4052
|
const m = (name, fn) => A.addMethod(name, fn);
|
|
3300
4053
|
m("toBe", function(expected) {
|
|
3301
|
-
this.assert(
|
|
4054
|
+
this.assert(
|
|
4055
|
+
Object.is(this._obj, expected),
|
|
4056
|
+
"expected #{this} to be #{exp}",
|
|
4057
|
+
"expected #{this} not to be #{exp}",
|
|
4058
|
+
expected,
|
|
4059
|
+
this._obj
|
|
4060
|
+
);
|
|
3302
4061
|
});
|
|
3303
4062
|
m("toEqual", function(expected) {
|
|
3304
|
-
this.assert(
|
|
4063
|
+
this.assert(
|
|
4064
|
+
utils.eql(this._obj, expected),
|
|
4065
|
+
"expected #{this} to deeply equal #{exp}",
|
|
4066
|
+
"expected #{this} not to deeply equal #{exp}",
|
|
4067
|
+
expected,
|
|
4068
|
+
this._obj,
|
|
4069
|
+
true
|
|
4070
|
+
);
|
|
3305
4071
|
});
|
|
3306
4072
|
m("toBeTruthy", function() {
|
|
3307
|
-
this.assert(
|
|
4073
|
+
this.assert(
|
|
4074
|
+
Boolean(this._obj),
|
|
4075
|
+
"expected #{this} to be truthy",
|
|
4076
|
+
"expected #{this} not to be truthy"
|
|
4077
|
+
);
|
|
3308
4078
|
});
|
|
3309
4079
|
m("toBeFalsy", function() {
|
|
3310
4080
|
this.assert(!this._obj, "expected #{this} to be falsy", "expected #{this} not to be falsy");
|
|
3311
4081
|
});
|
|
3312
4082
|
m("toBeNull", function() {
|
|
3313
|
-
this.assert(
|
|
4083
|
+
this.assert(
|
|
4084
|
+
this._obj === null,
|
|
4085
|
+
"expected #{this} to be null",
|
|
4086
|
+
"expected #{this} not to be null"
|
|
4087
|
+
);
|
|
3314
4088
|
});
|
|
3315
4089
|
m("toBeUndefined", function() {
|
|
3316
|
-
this.assert(
|
|
4090
|
+
this.assert(
|
|
4091
|
+
this._obj === void 0,
|
|
4092
|
+
"expected #{this} to be undefined",
|
|
4093
|
+
"expected #{this} not to be undefined"
|
|
4094
|
+
);
|
|
3317
4095
|
});
|
|
3318
4096
|
m("toBeDefined", function() {
|
|
3319
|
-
this.assert(
|
|
4097
|
+
this.assert(
|
|
4098
|
+
this._obj !== void 0,
|
|
4099
|
+
"expected #{this} to be defined",
|
|
4100
|
+
"expected #{this} to be undefined"
|
|
4101
|
+
);
|
|
3320
4102
|
});
|
|
3321
4103
|
m("toBeNaN", function() {
|
|
3322
|
-
this.assert(
|
|
4104
|
+
this.assert(
|
|
4105
|
+
Number.isNaN(this._obj),
|
|
4106
|
+
"expected #{this} to be NaN",
|
|
4107
|
+
"expected #{this} not to be NaN"
|
|
4108
|
+
);
|
|
3323
4109
|
});
|
|
3324
4110
|
const compare = (name, op, word) => m(name, function(expected) {
|
|
3325
|
-
this.assert(
|
|
4111
|
+
this.assert(
|
|
4112
|
+
op(this._obj, expected),
|
|
4113
|
+
`expected #{this} to be ${word} #{exp}`,
|
|
4114
|
+
`expected #{this} not to be ${word} #{exp}`,
|
|
4115
|
+
expected
|
|
4116
|
+
);
|
|
3326
4117
|
});
|
|
3327
4118
|
compare("toBeGreaterThan", (a, b) => a > b, "greater than");
|
|
3328
4119
|
compare("toBeGreaterThanOrEqual", (a, b) => a >= b, "greater than or equal to");
|
|
@@ -3330,46 +4121,76 @@ function jestMatchers(chai, utils) {
|
|
|
3330
4121
|
compare("toBeLessThanOrEqual", (a, b) => a <= b, "less than or equal to");
|
|
3331
4122
|
m("toBeCloseTo", function(expected, numDigits = 2) {
|
|
3332
4123
|
const pass = Math.abs(expected - this._obj) < 10 ** -numDigits / 2;
|
|
3333
|
-
this.assert(
|
|
4124
|
+
this.assert(
|
|
4125
|
+
pass,
|
|
4126
|
+
`expected #{this} to be close to #{exp} (${numDigits} digits)`,
|
|
4127
|
+
`expected #{this} not to be close to #{exp} (${numDigits} digits)`,
|
|
4128
|
+
expected
|
|
4129
|
+
);
|
|
3334
4130
|
});
|
|
3335
4131
|
m("toContain", function(item) {
|
|
3336
4132
|
const obj = this._obj;
|
|
3337
4133
|
const ok = typeof obj === "string" ? obj.includes(item) : Array.from(obj).includes(item);
|
|
3338
|
-
this.assert(
|
|
4134
|
+
this.assert(
|
|
4135
|
+
ok,
|
|
4136
|
+
"expected #{this} to contain #{exp}",
|
|
4137
|
+
"expected #{this} not to contain #{exp}",
|
|
4138
|
+
item
|
|
4139
|
+
);
|
|
3339
4140
|
});
|
|
3340
4141
|
m("toHaveLength", function(length) {
|
|
3341
|
-
const actual = this._obj == null ?
|
|
3342
|
-
this.assert(
|
|
4142
|
+
const actual = this._obj == null ? void 0 : this._obj.length;
|
|
4143
|
+
this.assert(
|
|
4144
|
+
actual === length,
|
|
4145
|
+
"expected #{this} to have length #{exp}",
|
|
4146
|
+
"expected #{this} not to have length #{exp}",
|
|
4147
|
+
length,
|
|
4148
|
+
actual
|
|
4149
|
+
);
|
|
3343
4150
|
});
|
|
3344
4151
|
m("toMatch", function(expected) {
|
|
3345
4152
|
const obj = this._obj;
|
|
3346
4153
|
const ok = expected instanceof RegExp ? expected.test(obj) : String(obj).includes(expected);
|
|
3347
|
-
this.assert(
|
|
4154
|
+
this.assert(
|
|
4155
|
+
ok,
|
|
4156
|
+
"expected #{this} to match #{exp}",
|
|
4157
|
+
"expected #{this} not to match #{exp}",
|
|
4158
|
+
expected
|
|
4159
|
+
);
|
|
3348
4160
|
});
|
|
3349
4161
|
m("toHaveProperty", function(path, ...rest) {
|
|
3350
4162
|
const keys = Array.isArray(path) ? path : String(path).split(".");
|
|
3351
4163
|
let cur = this._obj;
|
|
3352
4164
|
let found = true;
|
|
3353
4165
|
for (const k of keys) {
|
|
3354
|
-
if (cur != null && k in Object(cur))
|
|
3355
|
-
cur = cur[k];
|
|
4166
|
+
if (cur != null && k in Object(cur)) cur = cur[k];
|
|
3356
4167
|
else {
|
|
3357
4168
|
found = false;
|
|
3358
4169
|
break;
|
|
3359
4170
|
}
|
|
3360
4171
|
}
|
|
3361
4172
|
const pass = found && (rest.length === 0 || utils.eql(cur, rest[0]));
|
|
3362
|
-
this.assert(
|
|
4173
|
+
this.assert(
|
|
4174
|
+
pass,
|
|
4175
|
+
"expected #{this} to have property #{exp}",
|
|
4176
|
+
"expected #{this} not to have property #{exp}",
|
|
4177
|
+
path
|
|
4178
|
+
);
|
|
3363
4179
|
});
|
|
3364
4180
|
m("toBeInstanceOf", function(ctor) {
|
|
3365
|
-
this.assert(
|
|
4181
|
+
this.assert(
|
|
4182
|
+
this._obj instanceof ctor,
|
|
4183
|
+
"expected #{this} to be an instance of #{exp}",
|
|
4184
|
+
"expected #{this} not to be an instance of #{exp}",
|
|
4185
|
+
ctor.name ?? ctor
|
|
4186
|
+
);
|
|
3366
4187
|
});
|
|
3367
4188
|
m("toThrow", function(expected) {
|
|
3368
4189
|
const a = new chai.Assertion(this._obj);
|
|
3369
4190
|
if (utils.flag(this, "negate")) {
|
|
3370
|
-
expected ===
|
|
4191
|
+
expected === void 0 ? a.to.not.throw() : a.to.not.throw(expected);
|
|
3371
4192
|
} else {
|
|
3372
|
-
expected ===
|
|
4193
|
+
expected === void 0 ? a.to.throw() : a.to.throw(expected);
|
|
3373
4194
|
}
|
|
3374
4195
|
});
|
|
3375
4196
|
}
|
|
@@ -3377,13 +4198,13 @@ function jestMatchers(chai, utils) {
|
|
|
3377
4198
|
// deps/chai.js
|
|
3378
4199
|
use(jestMatchers);
|
|
3379
4200
|
export {
|
|
3380
|
-
|
|
3381
|
-
use,
|
|
3382
|
-
should,
|
|
3383
|
-
expect,
|
|
3384
|
-
config,
|
|
3385
|
-
assert,
|
|
3386
|
-
Should,
|
|
4201
|
+
Assertion,
|
|
3387
4202
|
AssertionError,
|
|
3388
|
-
|
|
4203
|
+
Should,
|
|
4204
|
+
assert,
|
|
4205
|
+
config,
|
|
4206
|
+
expect,
|
|
4207
|
+
should,
|
|
4208
|
+
use,
|
|
4209
|
+
utils_exports as util
|
|
3389
4210
|
};
|