chai 5.2.0 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/chai.js +397 -347
- package/eslint.config.js +1 -0
- package/lib/chai/assertion.js +167 -143
- package/lib/chai/core/assertions.js +108 -109
- package/lib/chai/interface/assert.js +13 -13
- package/lib/chai/interface/should.js +1 -1
- package/lib/chai/utils/addChainableMethod.js +12 -12
- package/lib/chai/utils/addMethod.js +3 -3
- package/lib/chai/utils/addProperty.js +2 -2
- package/lib/chai/utils/expectTypes.js +6 -6
- package/lib/chai/utils/flag.js +4 -3
- package/lib/chai/utils/getMessage.js +8 -8
- package/lib/chai/utils/getOperator.js +7 -7
- package/lib/chai/utils/getProperties.js +2 -2
- package/lib/chai/utils/inspect.js +1 -1
- package/lib/chai/utils/objDisplay.js +2 -2
- package/lib/chai/utils/overwriteChainableMethod.js +7 -7
- package/lib/chai/utils/overwriteMethod.js +5 -5
- package/lib/chai/utils/overwriteProperty.js +4 -4
- package/lib/chai/utils/proxify.js +10 -9
- package/lib/chai/utils/test.js +1 -1
- package/lib/chai/utils/transferFlags.js +2 -2
- package/package.json +6 -4
- package/tsconfig.json +18 -0
|
@@ -24,7 +24,7 @@ import {AssertionError} from 'assertion-error';
|
|
|
24
24
|
* @public
|
|
25
25
|
*/
|
|
26
26
|
export function assert(express, errmsg) {
|
|
27
|
-
|
|
27
|
+
let test = new Assertion(null, null, chai.assert, true);
|
|
28
28
|
test.assert(express, errmsg, '[ negation message unavailable ]');
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -122,7 +122,7 @@ assert.isNotOk = function (val, msg) {
|
|
|
122
122
|
* @public
|
|
123
123
|
*/
|
|
124
124
|
assert.equal = function (act, exp, msg) {
|
|
125
|
-
|
|
125
|
+
let test = new Assertion(act, msg, assert.equal, true);
|
|
126
126
|
|
|
127
127
|
test.assert(
|
|
128
128
|
exp == flag(test, 'object'),
|
|
@@ -149,7 +149,7 @@ assert.equal = function (act, exp, msg) {
|
|
|
149
149
|
* @public
|
|
150
150
|
*/
|
|
151
151
|
assert.notEqual = function (act, exp, msg) {
|
|
152
|
-
|
|
152
|
+
let test = new Assertion(act, msg, assert.notEqual, true);
|
|
153
153
|
|
|
154
154
|
test.assert(
|
|
155
155
|
exp != flag(test, 'object'),
|
|
@@ -1993,7 +1993,7 @@ assert.throws = function (fn, errorLike, errMsgMatcher, msg) {
|
|
|
1993
1993
|
errorLike = null;
|
|
1994
1994
|
}
|
|
1995
1995
|
|
|
1996
|
-
|
|
1996
|
+
let assertErr = new Assertion(fn, msg, assert.throws, true).to.throw(
|
|
1997
1997
|
errorLike,
|
|
1998
1998
|
errMsgMatcher
|
|
1999
1999
|
);
|
|
@@ -2057,7 +2057,7 @@ assert.doesNotThrow = function (fn, errorLike, errMsgMatcher, message) {
|
|
|
2057
2057
|
* @public
|
|
2058
2058
|
*/
|
|
2059
2059
|
assert.operator = function (val, operator, val2, msg) {
|
|
2060
|
-
|
|
2060
|
+
let ok;
|
|
2061
2061
|
switch (operator) {
|
|
2062
2062
|
case '==':
|
|
2063
2063
|
ok = val == val2;
|
|
@@ -2091,7 +2091,7 @@ assert.operator = function (val, operator, val2, msg) {
|
|
|
2091
2091
|
assert.operator
|
|
2092
2092
|
);
|
|
2093
2093
|
}
|
|
2094
|
-
|
|
2094
|
+
let test = new Assertion(ok, msg, assert.operator, true);
|
|
2095
2095
|
test.assert(
|
|
2096
2096
|
true === flag(test, 'object'),
|
|
2097
2097
|
'expected ' + inspect(val) + ' to be ' + operator + ' ' + inspect(val2),
|
|
@@ -2611,7 +2611,7 @@ assert.changes = function (fn, obj, prop, msg) {
|
|
|
2611
2611
|
*/
|
|
2612
2612
|
assert.changesBy = function (fn, obj, prop, delta, msg) {
|
|
2613
2613
|
if (arguments.length === 4 && typeof obj === 'function') {
|
|
2614
|
-
|
|
2614
|
+
let tmpMsg = delta;
|
|
2615
2615
|
delta = prop;
|
|
2616
2616
|
msg = tmpMsg;
|
|
2617
2617
|
} else if (arguments.length === 3) {
|
|
@@ -2672,7 +2672,7 @@ assert.doesNotChange = function (fn, obj, prop, msg) {
|
|
|
2672
2672
|
*/
|
|
2673
2673
|
assert.changesButNotBy = function (fn, obj, prop, delta, msg) {
|
|
2674
2674
|
if (arguments.length === 4 && typeof obj === 'function') {
|
|
2675
|
-
|
|
2675
|
+
let tmpMsg = delta;
|
|
2676
2676
|
delta = prop;
|
|
2677
2677
|
msg = tmpMsg;
|
|
2678
2678
|
} else if (arguments.length === 3) {
|
|
@@ -2732,7 +2732,7 @@ assert.increases = function (fn, obj, prop, msg) {
|
|
|
2732
2732
|
*/
|
|
2733
2733
|
assert.increasesBy = function (fn, obj, prop, delta, msg) {
|
|
2734
2734
|
if (arguments.length === 4 && typeof obj === 'function') {
|
|
2735
|
-
|
|
2735
|
+
let tmpMsg = delta;
|
|
2736
2736
|
delta = prop;
|
|
2737
2737
|
msg = tmpMsg;
|
|
2738
2738
|
} else if (arguments.length === 3) {
|
|
@@ -2795,7 +2795,7 @@ assert.doesNotIncrease = function (fn, obj, prop, msg) {
|
|
|
2795
2795
|
*/
|
|
2796
2796
|
assert.increasesButNotBy = function (fn, obj, prop, delta, msg) {
|
|
2797
2797
|
if (arguments.length === 4 && typeof obj === 'function') {
|
|
2798
|
-
|
|
2798
|
+
let tmpMsg = delta;
|
|
2799
2799
|
delta = prop;
|
|
2800
2800
|
msg = tmpMsg;
|
|
2801
2801
|
} else if (arguments.length === 3) {
|
|
@@ -2855,7 +2855,7 @@ assert.decreases = function (fn, obj, prop, msg) {
|
|
|
2855
2855
|
*/
|
|
2856
2856
|
assert.decreasesBy = function (fn, obj, prop, delta, msg) {
|
|
2857
2857
|
if (arguments.length === 4 && typeof obj === 'function') {
|
|
2858
|
-
|
|
2858
|
+
let tmpMsg = delta;
|
|
2859
2859
|
delta = prop;
|
|
2860
2860
|
msg = tmpMsg;
|
|
2861
2861
|
} else if (arguments.length === 3) {
|
|
@@ -2919,7 +2919,7 @@ assert.doesNotDecrease = function (fn, obj, prop, msg) {
|
|
|
2919
2919
|
*/
|
|
2920
2920
|
assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) {
|
|
2921
2921
|
if (arguments.length === 4 && typeof obj === 'function') {
|
|
2922
|
-
|
|
2922
|
+
let tmpMsg = delta;
|
|
2923
2923
|
delta = prop;
|
|
2924
2924
|
msg = tmpMsg;
|
|
2925
2925
|
} else if (arguments.length === 3) {
|
|
@@ -2952,7 +2952,7 @@ assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) {
|
|
|
2952
2952
|
*/
|
|
2953
2953
|
assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) {
|
|
2954
2954
|
if (arguments.length === 4 && typeof obj === 'function') {
|
|
2955
|
-
|
|
2955
|
+
let tmpMsg = delta;
|
|
2956
2956
|
delta = prop;
|
|
2957
2957
|
msg = tmpMsg;
|
|
2958
2958
|
} else if (arguments.length === 3) {
|
|
@@ -15,13 +15,13 @@ import {transferFlags} from './transferFlags.js';
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
// Check whether `Object.setPrototypeOf` is supported
|
|
18
|
-
|
|
18
|
+
let canSetPrototype = typeof Object.setPrototypeOf === 'function';
|
|
19
19
|
|
|
20
20
|
// Without `Object.setPrototypeOf` support, this module will need to add properties to a function.
|
|
21
21
|
// However, some of functions' own props are not configurable and should be skipped.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
let testFn = function () {};
|
|
23
|
+
let excludeNames = Object.getOwnPropertyNames(testFn).filter(function (name) {
|
|
24
|
+
let propDesc = Object.getOwnPropertyDescriptor(testFn, name);
|
|
25
25
|
|
|
26
26
|
// Note: PhantomJS 1.x includes `callee` as one of `testFn`'s own properties,
|
|
27
27
|
// but then returns `undefined` as the property descriptor for `callee`. As a
|
|
@@ -33,7 +33,7 @@ var excludeNames = Object.getOwnPropertyNames(testFn).filter(function (name) {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// Cache `Function` properties
|
|
36
|
-
|
|
36
|
+
let call = Function.prototype.call,
|
|
37
37
|
apply = Function.prototype.apply;
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -69,7 +69,7 @@ export function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
|
69
69
|
chainingBehavior = function () {};
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
let chainableBehavior = {
|
|
73
73
|
method: method,
|
|
74
74
|
chainingBehavior: chainingBehavior
|
|
75
75
|
};
|
|
@@ -84,7 +84,7 @@ export function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
|
84
84
|
get: function chainableMethodGetter() {
|
|
85
85
|
chainableBehavior.chainingBehavior.call(this);
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
let chainableMethodWrapper = function () {
|
|
88
88
|
// Setting the `ssfi` flag to `chainableMethodWrapper` causes this
|
|
89
89
|
// function to be the starting point for removing implementation
|
|
90
90
|
// frames from the stack trace of a failed assertion.
|
|
@@ -104,12 +104,12 @@ export function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
|
104
104
|
flag(this, 'ssfi', chainableMethodWrapper);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
let result = chainableBehavior.method.apply(this, arguments);
|
|
108
108
|
if (result !== undefined) {
|
|
109
109
|
return result;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
let newAssertion = new Assertion();
|
|
113
113
|
transferFlags(this, newAssertion);
|
|
114
114
|
return newAssertion;
|
|
115
115
|
};
|
|
@@ -119,7 +119,7 @@ export function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
|
119
119
|
// Use `Object.setPrototypeOf` if available
|
|
120
120
|
if (canSetPrototype) {
|
|
121
121
|
// Inherit all properties from the object by replacing the `Function` prototype
|
|
122
|
-
|
|
122
|
+
let prototype = Object.create(this);
|
|
123
123
|
// Restore the `call` and `apply` methods from `Function`
|
|
124
124
|
prototype.call = call;
|
|
125
125
|
prototype.apply = apply;
|
|
@@ -127,13 +127,13 @@ export function addChainableMethod(ctx, name, method, chainingBehavior) {
|
|
|
127
127
|
}
|
|
128
128
|
// Otherwise, redefine all properties (slow!)
|
|
129
129
|
else {
|
|
130
|
-
|
|
130
|
+
let asserterNames = Object.getOwnPropertyNames(ctx);
|
|
131
131
|
asserterNames.forEach(function (asserterName) {
|
|
132
132
|
if (excludeNames.indexOf(asserterName) !== -1) {
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
let pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
|
|
137
137
|
Object.defineProperty(chainableMethodWrapper, asserterName, pd);
|
|
138
138
|
});
|
|
139
139
|
}
|
|
@@ -36,7 +36,7 @@ import {Assertion} from '../assertion.js';
|
|
|
36
36
|
* @public
|
|
37
37
|
*/
|
|
38
38
|
export function addMethod(ctx, name, method) {
|
|
39
|
-
|
|
39
|
+
let methodWrapper = function () {
|
|
40
40
|
// Setting the `ssfi` flag to `methodWrapper` causes this function to be the
|
|
41
41
|
// starting point for removing implementation frames from the stack trace of
|
|
42
42
|
// a failed assertion.
|
|
@@ -53,10 +53,10 @@ export function addMethod(ctx, name, method) {
|
|
|
53
53
|
flag(this, 'ssfi', methodWrapper);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
let result = method.apply(this, arguments);
|
|
57
57
|
if (result !== undefined) return result;
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
let newAssertion = new Assertion();
|
|
60
60
|
transferFlags(this, newAssertion);
|
|
61
61
|
return newAssertion;
|
|
62
62
|
};
|
|
@@ -58,10 +58,10 @@ export function addProperty(ctx, name, getter) {
|
|
|
58
58
|
flag(this, 'ssfi', propertyGetter);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
let result = getter.call(this);
|
|
62
62
|
if (result !== undefined) return result;
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
let newAssertion = new Assertion();
|
|
65
65
|
transferFlags(this, newAssertion);
|
|
66
66
|
return newAssertion;
|
|
67
67
|
},
|
|
@@ -22,8 +22,8 @@ import {type} from './type-detect.js';
|
|
|
22
22
|
* @public
|
|
23
23
|
*/
|
|
24
24
|
export function expectTypes(obj, types) {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let flagMsg = flag(obj, 'message');
|
|
26
|
+
let ssfi = flag(obj, 'ssfi');
|
|
27
27
|
|
|
28
28
|
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
29
29
|
|
|
@@ -34,15 +34,15 @@ export function expectTypes(obj, types) {
|
|
|
34
34
|
types.sort();
|
|
35
35
|
|
|
36
36
|
// Transforms ['lorem', 'ipsum'] into 'a lorem, or an ipsum'
|
|
37
|
-
|
|
37
|
+
let str = types
|
|
38
38
|
.map(function (t, index) {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
let art = ~['a', 'e', 'i', 'o', 'u'].indexOf(t.charAt(0)) ? 'an' : 'a';
|
|
40
|
+
let or = types.length > 1 && index === types.length - 1 ? 'or ' : '';
|
|
41
41
|
return or + art + ' ' + t;
|
|
42
42
|
})
|
|
43
43
|
.join(', ');
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
let objType = type(obj).toLowerCase();
|
|
46
46
|
|
|
47
47
|
if (
|
|
48
48
|
!types.some(function (expected) {
|
package/lib/chai/utils/flag.js
CHANGED
|
@@ -15,16 +15,17 @@
|
|
|
15
15
|
* utils.flag(this, 'foo', 'bar'); // setter
|
|
16
16
|
* utils.flag(this, 'foo'); // getter, returns `bar`
|
|
17
17
|
*
|
|
18
|
-
* @
|
|
18
|
+
* @template {{__flags?: {[key: PropertyKey]: unknown}}} T
|
|
19
|
+
* @param {T} obj object constructed Assertion
|
|
19
20
|
* @param {string} key
|
|
20
|
-
* @param {unknown} value
|
|
21
|
+
* @param {unknown} [value]
|
|
21
22
|
* @namespace Utils
|
|
22
23
|
* @name flag
|
|
23
24
|
* @returns {unknown | undefined}
|
|
24
25
|
* @private
|
|
25
26
|
*/
|
|
26
27
|
export function flag(obj, key, value) {
|
|
27
|
-
|
|
28
|
+
let flags = obj.__flags || (obj.__flags = Object.create(null));
|
|
28
29
|
if (arguments.length === 3) {
|
|
29
30
|
flags[key] = value;
|
|
30
31
|
} else {
|
|
@@ -21,19 +21,19 @@ import {objDisplay} from './objDisplay.js';
|
|
|
21
21
|
* - `#{exp}` expected value
|
|
22
22
|
*
|
|
23
23
|
* @param {object} obj object (constructed Assertion)
|
|
24
|
-
* @param {
|
|
25
|
-
* @returns {
|
|
24
|
+
* @param {IArguments} args chai.Assertion.prototype.assert arguments
|
|
25
|
+
* @returns {string}
|
|
26
26
|
* @namespace Utils
|
|
27
27
|
* @name getMessage
|
|
28
28
|
* @public
|
|
29
29
|
*/
|
|
30
30
|
export function getMessage(obj, args) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
let negate = flag(obj, 'negate');
|
|
32
|
+
let val = flag(obj, 'object');
|
|
33
|
+
let expected = args[3];
|
|
34
|
+
let actual = getActual(obj, args);
|
|
35
|
+
let msg = negate ? args[2] : args[1];
|
|
36
|
+
let flagMsg = flag(obj, 'message');
|
|
37
37
|
|
|
38
38
|
if (typeof msg === 'function') msg = msg();
|
|
39
39
|
msg = msg || '';
|
|
@@ -6,8 +6,8 @@ import {type} from './type-detect.js';
|
|
|
6
6
|
* @returns {boolean}
|
|
7
7
|
*/
|
|
8
8
|
function isObjectType(obj) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
let objectType = type(obj);
|
|
10
|
+
let objectTypes = ['Array', 'Object', 'Function'];
|
|
11
11
|
|
|
12
12
|
return objectTypes.indexOf(objectType) !== -1;
|
|
13
13
|
}
|
|
@@ -29,10 +29,10 @@ function isObjectType(obj) {
|
|
|
29
29
|
* @public
|
|
30
30
|
*/
|
|
31
31
|
export function getOperator(obj, args) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
let operator = flag(obj, 'operator');
|
|
33
|
+
let negate = flag(obj, 'negate');
|
|
34
|
+
let expected = args[3];
|
|
35
|
+
let msg = negate ? args[2] : args[1];
|
|
36
36
|
|
|
37
37
|
if (operator) {
|
|
38
38
|
return operator;
|
|
@@ -49,7 +49,7 @@ export function getOperator(obj, args) {
|
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
let isObject = isObjectType(expected);
|
|
53
53
|
if (/\snot\s/.test(msg)) {
|
|
54
54
|
return isObject ? 'notDeepStrictEqual' : 'notStrictEqual';
|
|
55
55
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
export function getProperties(object) {
|
|
20
|
-
|
|
20
|
+
let result = Object.getOwnPropertyNames(object);
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @param {unknown} property
|
|
@@ -28,7 +28,7 @@ export function getProperties(object) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
let proto = Object.getPrototypeOf(object);
|
|
32
32
|
while (proto !== null) {
|
|
33
33
|
Object.getOwnPropertyNames(proto).forEach(addProperty);
|
|
34
34
|
proto = Object.getPrototypeOf(proto);
|
|
@@ -21,7 +21,7 @@ import {config} from '../config.js';
|
|
|
21
21
|
* @public
|
|
22
22
|
*/
|
|
23
23
|
export function objDisplay(obj) {
|
|
24
|
-
|
|
24
|
+
let str = inspect(obj),
|
|
25
25
|
type = Object.prototype.toString.call(obj);
|
|
26
26
|
|
|
27
27
|
if (config.truncateThreshold && str.length >= config.truncateThreshold) {
|
|
@@ -32,7 +32,7 @@ export function objDisplay(obj) {
|
|
|
32
32
|
} else if (type === '[object Array]') {
|
|
33
33
|
return '[ Array(' + obj.length + ') ]';
|
|
34
34
|
} else if (type === '[object Object]') {
|
|
35
|
-
|
|
35
|
+
let keys = Object.keys(obj),
|
|
36
36
|
kstr =
|
|
37
37
|
keys.length > 2
|
|
38
38
|
? keys.splice(0, 2).join(', ') + ', ...'
|
|
@@ -40,29 +40,29 @@ import {transferFlags} from './transferFlags.js';
|
|
|
40
40
|
* @public
|
|
41
41
|
*/
|
|
42
42
|
export function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
|
|
43
|
-
|
|
43
|
+
let chainableBehavior = ctx.__methods[name];
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
let _chainingBehavior = chainableBehavior.chainingBehavior;
|
|
46
46
|
chainableBehavior.chainingBehavior =
|
|
47
47
|
function overwritingChainableMethodGetter() {
|
|
48
|
-
|
|
48
|
+
let result = chainingBehavior(_chainingBehavior).call(this);
|
|
49
49
|
if (result !== undefined) {
|
|
50
50
|
return result;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
let newAssertion = new Assertion();
|
|
54
54
|
transferFlags(this, newAssertion);
|
|
55
55
|
return newAssertion;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
let _method = chainableBehavior.method;
|
|
59
59
|
chainableBehavior.method = function overwritingChainableMethodWrapper() {
|
|
60
|
-
|
|
60
|
+
let result = method(_method).apply(this, arguments);
|
|
61
61
|
if (result !== undefined) {
|
|
62
62
|
return result;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
let newAssertion = new Assertion();
|
|
66
66
|
transferFlags(this, newAssertion);
|
|
67
67
|
return newAssertion;
|
|
68
68
|
};
|
|
@@ -44,14 +44,14 @@ import {transferFlags} from './transferFlags.js';
|
|
|
44
44
|
* @public
|
|
45
45
|
*/
|
|
46
46
|
export function overwriteMethod(ctx, name, method) {
|
|
47
|
-
|
|
47
|
+
let _method = ctx[name],
|
|
48
48
|
_super = function () {
|
|
49
49
|
throw new Error(name + ' is not a function');
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
if (_method && 'function' === typeof _method) _super = _method;
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
let overwritingMethodWrapper = function () {
|
|
55
55
|
// Setting the `ssfi` flag to `overwritingMethodWrapper` causes this
|
|
56
56
|
// function to be the starting point for removing implementation frames from
|
|
57
57
|
// the stack trace of a failed assertion.
|
|
@@ -71,16 +71,16 @@ export function overwriteMethod(ctx, name, method) {
|
|
|
71
71
|
// Setting the `lockSsfi` flag to `true` prevents the overwritten assertion
|
|
72
72
|
// from changing the `ssfi` flag. By this point, the `ssfi` flag is already
|
|
73
73
|
// set to the correct starting point for this assertion.
|
|
74
|
-
|
|
74
|
+
let origLockSsfi = flag(this, 'lockSsfi');
|
|
75
75
|
flag(this, 'lockSsfi', true);
|
|
76
|
-
|
|
76
|
+
let result = method(_super).apply(this, arguments);
|
|
77
77
|
flag(this, 'lockSsfi', origLockSsfi);
|
|
78
78
|
|
|
79
79
|
if (result !== undefined) {
|
|
80
80
|
return result;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
let newAssertion = new Assertion();
|
|
84
84
|
transferFlags(this, newAssertion);
|
|
85
85
|
return newAssertion;
|
|
86
86
|
};
|
|
@@ -42,7 +42,7 @@ import {transferFlags} from './transferFlags.js';
|
|
|
42
42
|
* @public
|
|
43
43
|
*/
|
|
44
44
|
export function overwriteProperty(ctx, name, getter) {
|
|
45
|
-
|
|
45
|
+
let _get = Object.getOwnPropertyDescriptor(ctx, name),
|
|
46
46
|
_super = function () {};
|
|
47
47
|
|
|
48
48
|
if (_get && 'function' === typeof _get.get) _super = _get.get;
|
|
@@ -71,16 +71,16 @@ export function overwriteProperty(ctx, name, getter) {
|
|
|
71
71
|
// Setting the `lockSsfi` flag to `true` prevents the overwritten
|
|
72
72
|
// assertion from changing the `ssfi` flag. By this point, the `ssfi`
|
|
73
73
|
// flag is already set to the correct starting point for this assertion.
|
|
74
|
-
|
|
74
|
+
let origLockSsfi = flag(this, 'lockSsfi');
|
|
75
75
|
flag(this, 'lockSsfi', true);
|
|
76
|
-
|
|
76
|
+
let result = getter(_super).call(this);
|
|
77
77
|
flag(this, 'lockSsfi', origLockSsfi);
|
|
78
78
|
|
|
79
79
|
if (result !== undefined) {
|
|
80
80
|
return result;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
let newAssertion = new Assertion();
|
|
84
84
|
transferFlags(this, newAssertion);
|
|
85
85
|
return newAssertion;
|
|
86
86
|
},
|
|
@@ -9,6 +9,7 @@ import {isProxyEnabled} from './isProxyEnabled.js';
|
|
|
9
9
|
* MIT Licensed
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
/** @type {PropertyKey[]} */
|
|
12
13
|
const builtins = ['__flags', '__methods', '_obj', 'assert'];
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -24,11 +25,11 @@ const builtins = ['__flags', '__methods', '_obj', 'assert'];
|
|
|
24
25
|
* If proxies are unsupported or disabled via the user's Chai config, then
|
|
25
26
|
* return object without modification.
|
|
26
27
|
*
|
|
27
|
-
* @param {object} obj
|
|
28
|
-
* @param {string} nonChainableMethodName
|
|
29
|
-
* @returns {unknown}
|
|
30
28
|
* @namespace Utils
|
|
31
|
-
* @
|
|
29
|
+
* @template {object} T
|
|
30
|
+
* @param {T} obj
|
|
31
|
+
* @param {string} [nonChainableMethodName]
|
|
32
|
+
* @returns {T}
|
|
32
33
|
*/
|
|
33
34
|
export function proxify(obj, nonChainableMethodName) {
|
|
34
35
|
if (!isProxyEnabled()) return obj;
|
|
@@ -60,8 +61,8 @@ export function proxify(obj, nonChainableMethodName) {
|
|
|
60
61
|
// If the property is reasonably close to an existing Chai property,
|
|
61
62
|
// suggest that property to the user. Only suggest properties with a
|
|
62
63
|
// distance less than 4.
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
let suggestion = null;
|
|
65
|
+
let suggestionDistance = 4;
|
|
65
66
|
getProperties(target).forEach(function (prop) {
|
|
66
67
|
if (
|
|
67
68
|
// we actually mean to check `Object.prototype` here
|
|
@@ -69,7 +70,7 @@ export function proxify(obj, nonChainableMethodName) {
|
|
|
69
70
|
!Object.prototype.hasOwnProperty(prop) &&
|
|
70
71
|
builtins.indexOf(prop) === -1
|
|
71
72
|
) {
|
|
72
|
-
|
|
73
|
+
let dist = stringDistanceCapped(property, prop, suggestionDistance);
|
|
73
74
|
if (dist < suggestionDistance) {
|
|
74
75
|
suggestion = prop;
|
|
75
76
|
suggestionDistance = dist;
|
|
@@ -126,7 +127,7 @@ function stringDistanceCapped(strA, strB, cap) {
|
|
|
126
127
|
return cap;
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
|
|
130
|
+
let memo = [];
|
|
130
131
|
// `memo` is a two-dimensional array containing distances.
|
|
131
132
|
// memo[i][j] is the distance between strA.slice(0, i) and
|
|
132
133
|
// strB.slice(0, j).
|
|
@@ -139,7 +140,7 @@ function stringDistanceCapped(strA, strB, cap) {
|
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
for (let i = 1; i <= strA.length; i++) {
|
|
142
|
-
|
|
143
|
+
let ch = strA.charCodeAt(i - 1);
|
|
143
144
|
for (let j = 1; j <= strB.length; j++) {
|
|
144
145
|
if (Math.abs(i - j) >= cap) {
|
|
145
146
|
memo[i][j] = cap;
|
package/lib/chai/utils/test.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @private
|
|
27
27
|
*/
|
|
28
28
|
export function transferFlags(assertion, object, includeAll) {
|
|
29
|
-
|
|
29
|
+
let flags = assertion.__flags || (assertion.__flags = Object.create(null));
|
|
30
30
|
|
|
31
31
|
if (!object.__flags) {
|
|
32
32
|
object.__flags = Object.create(null);
|
|
@@ -34,7 +34,7 @@ export function transferFlags(assertion, object, includeAll) {
|
|
|
34
34
|
|
|
35
35
|
includeAll = arguments.length === 3 ? includeAll : true;
|
|
36
36
|
|
|
37
|
-
for (
|
|
37
|
+
for (let flag in flags) {
|
|
38
38
|
if (
|
|
39
39
|
includeAll ||
|
|
40
40
|
(flag !== 'object' &&
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"Veselin Todorov <hi@vesln.com>",
|
|
19
19
|
"John Firebaugh <john.firebaugh@gmail.com>"
|
|
20
20
|
],
|
|
21
|
-
"version": "5.2.
|
|
21
|
+
"version": "5.2.1",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
24
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -39,10 +39,11 @@
|
|
|
39
39
|
"lint": "npm run lint:js && npm run lint:format",
|
|
40
40
|
"lint:js": "eslint lib/",
|
|
41
41
|
"lint:format": "prettier --check lib",
|
|
42
|
+
"lint:types": "tsc",
|
|
42
43
|
"clean": "rm -rf chai.js coverage/"
|
|
43
44
|
},
|
|
44
45
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
46
|
+
"node": ">=18"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"assertion-error": "^2.0.1",
|
|
@@ -58,10 +59,11 @@
|
|
|
58
59
|
"@web/test-runner": "^0.18.0",
|
|
59
60
|
"@web/test-runner-playwright": "^0.11.0",
|
|
60
61
|
"c8": "^10.1.3",
|
|
61
|
-
"esbuild": "^0.
|
|
62
|
+
"esbuild": "^0.25.0",
|
|
62
63
|
"eslint": "^8.56.0",
|
|
63
64
|
"eslint-plugin-jsdoc": "^48.0.4",
|
|
64
65
|
"mocha": "^10.2.0",
|
|
65
|
-
"prettier": "^3.4.2"
|
|
66
|
+
"prettier": "^3.4.2",
|
|
67
|
+
"typescript": "~5.7.3"
|
|
66
68
|
}
|
|
67
69
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"moduleResolution": "nodenext",
|
|
6
|
+
"types": [],
|
|
7
|
+
"checkJs": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"noUnusedParameters": true
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"lib/**/*.js"
|
|
17
|
+
]
|
|
18
|
+
}
|