chai 4.3.10 → 5.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +7 -1
- package/README.md +13 -71
- package/chai.js +3616 -11088
- package/eslint.config.js +12 -0
- package/index.js +1 -1
- package/lib/chai/assertion.js +152 -163
- package/lib/chai/config.js +35 -15
- package/lib/chai/core/assertions.js +3737 -3656
- package/lib/chai/interface/assert.js +2984 -3046
- package/lib/chai/interface/expect.js +45 -37
- package/lib/chai/interface/should.js +203 -201
- package/lib/chai/utils/addChainableMethod.js +14 -19
- package/lib/chai/utils/addLengthGuard.js +6 -6
- package/lib/chai/utils/addMethod.js +13 -14
- package/lib/chai/utils/addProperty.js +12 -13
- package/lib/chai/utils/compareByInspect.js +7 -12
- package/lib/chai/utils/expectTypes.js +9 -10
- package/lib/chai/utils/flag.js +7 -7
- package/lib/chai/utils/getActual.js +5 -5
- package/lib/chai/utils/getEnumerableProperties.js +2 -3
- package/lib/chai/utils/getMessage.js +9 -13
- package/lib/chai/utils/getOperator.js +13 -10
- package/lib/chai/utils/getOwnEnumerableProperties.js +5 -10
- package/lib/chai/utils/getOwnEnumerablePropertySymbols.js +4 -5
- package/lib/chai/utils/getProperties.js +7 -5
- package/lib/chai/utils/index.js +74 -140
- package/lib/chai/utils/inspect.js +9 -11
- package/lib/chai/utils/isNaN.js +5 -5
- package/lib/chai/utils/isProxyEnabled.js +4 -4
- package/lib/chai/utils/objDisplay.js +6 -11
- package/lib/chai/utils/overwriteChainableMethod.js +13 -14
- package/lib/chai/utils/overwriteMethod.js +18 -19
- package/lib/chai/utils/overwriteProperty.js +17 -19
- package/lib/chai/utils/proxify.js +15 -15
- package/lib/chai/utils/test.js +6 -10
- package/lib/chai/utils/transferFlags.js +6 -8
- package/lib/chai/utils/type-detect.js +20 -0
- package/lib/chai.js +35 -62
- package/package.json +25 -27
- package/register-assert.cjs +3 -0
- package/register-assert.js +3 -1
- package/register-expect.cjs +3 -0
- package/register-expect.js +3 -1
- package/register-should.cjs +3 -0
- package/register-should.js +3 -1
- package/web-test-runner.config.js +20 -0
- package/bower.json +0 -26
- package/index.mjs +0 -14
- package/karma.conf.js +0 -34
- package/karma.sauce.js +0 -41
- package/sauce.browsers.js +0 -106
package/eslint.config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import jsdoc from "eslint-plugin-jsdoc";
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
jsdoc.configs["flat/recommended"],
|
|
5
|
+
{
|
|
6
|
+
rules: {
|
|
7
|
+
"jsdoc/require-param-description": "off",
|
|
8
|
+
"jsdoc/require-returns-description": "off",
|
|
9
|
+
"jsdoc/tag-lines": ["error", "any", { startLines: 1 }],
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
];
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './lib/chai.js';
|
package/lib/chai/assertion.js
CHANGED
|
@@ -5,171 +5,160 @@
|
|
|
5
5
|
* MIT Licensed
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
8
|
+
import {config} from './config.js';
|
|
9
|
+
import {AssertionError} from 'assertion-error';
|
|
10
|
+
import * as util from './utils/index.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Assertion Constructor
|
|
14
|
+
*
|
|
15
|
+
* Creates object for chaining.
|
|
16
|
+
*
|
|
17
|
+
* `Assertion` objects contain metadata in the form of flags. Three flags can
|
|
18
|
+
* be assigned during instantiation by passing arguments to this constructor:
|
|
19
|
+
*
|
|
20
|
+
* - `object`: This flag contains the target of the assertion. For example, in
|
|
21
|
+
* the assertion `expect(numKittens).to.equal(7);`, the `object` flag will
|
|
22
|
+
* contain `numKittens` so that the `equal` assertion can reference it when
|
|
23
|
+
* needed.
|
|
24
|
+
*
|
|
25
|
+
* - `message`: This flag contains an optional custom error message to be
|
|
26
|
+
* prepended to the error message that's generated by the assertion when it
|
|
27
|
+
* fails.
|
|
28
|
+
*
|
|
29
|
+
* - `ssfi`: This flag stands for "start stack function indicator". It
|
|
30
|
+
* contains a function reference that serves as the starting point for
|
|
31
|
+
* removing frames from the stack trace of the error that's created by the
|
|
32
|
+
* assertion when it fails. The goal is to provide a cleaner stack trace to
|
|
33
|
+
* end users by removing Chai's internal functions. Note that it only works
|
|
34
|
+
* in environments that support `Error.captureStackTrace`, and only when
|
|
35
|
+
* `Chai.config.includeStack` hasn't been set to `false`.
|
|
36
|
+
*
|
|
37
|
+
* - `lockSsfi`: This flag controls whether or not the given `ssfi` flag
|
|
38
|
+
* should retain its current value, even as assertions are chained off of
|
|
39
|
+
* this object. This is usually set to `true` when creating a new assertion
|
|
40
|
+
* from within another assertion. It's also temporarily set to `true` before
|
|
41
|
+
* an overwritten assertion gets called by the overwriting assertion.
|
|
42
|
+
*
|
|
43
|
+
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
|
|
44
|
+
*
|
|
45
|
+
* @param {unknown} obj target of the assertion
|
|
46
|
+
* @param {string} msg (optional) custom error message
|
|
47
|
+
* @param {Function} ssfi (optional) starting point for removing stack frames
|
|
48
|
+
* @param {boolean} lockSsfi (optional) whether or not the ssfi flag is locked
|
|
49
|
+
* @returns {unknown}
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
export function Assertion (obj, msg, ssfi, lockSsfi) {
|
|
53
|
+
util.flag(this, 'ssfi', ssfi || Assertion);
|
|
54
|
+
util.flag(this, 'lockSsfi', lockSsfi);
|
|
55
|
+
util.flag(this, 'object', obj);
|
|
56
|
+
util.flag(this, 'message', msg);
|
|
57
|
+
util.flag(this, 'eql', config.deepEqual || util.eql);
|
|
58
|
+
|
|
59
|
+
return util.proxify(this);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Object.defineProperty(Assertion, 'includeStack', {
|
|
63
|
+
get: function() {
|
|
64
|
+
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
|
|
65
|
+
return config.includeStack;
|
|
66
|
+
},
|
|
67
|
+
set: function(value) {
|
|
68
|
+
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
|
|
69
|
+
config.includeStack = value;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
Object.defineProperty(Assertion, 'showDiff', {
|
|
74
|
+
get: function() {
|
|
75
|
+
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
|
|
76
|
+
return config.showDiff;
|
|
77
|
+
},
|
|
78
|
+
set: function(value) {
|
|
79
|
+
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
|
|
80
|
+
config.showDiff = value;
|
|
69
81
|
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
Assertion.addProperty = function (name, fn) {
|
|
85
|
+
util.addProperty(this.prototype, name, fn);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
Assertion.addMethod = function (name, fn) {
|
|
89
|
+
util.addMethod(this.prototype, name, fn);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
|
|
93
|
+
util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
Assertion.overwriteProperty = function (name, fn) {
|
|
97
|
+
util.overwriteProperty(this.prototype, name, fn);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Assertion.overwriteMethod = function (name, fn) {
|
|
101
|
+
util.overwriteMethod(this.prototype, name, fn);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
|
|
105
|
+
util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
106
|
+
};
|
|
70
107
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
108
|
+
/**
|
|
109
|
+
* ### .assert(expression, message, negateMessage, expected, actual, showDiff)
|
|
110
|
+
*
|
|
111
|
+
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
|
|
112
|
+
*
|
|
113
|
+
* @name assert
|
|
114
|
+
* @param {unknown} expression to be tested
|
|
115
|
+
* @param {string | Function} message or function that returns message to display if expression fails
|
|
116
|
+
* @param {string | Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
|
|
117
|
+
* @param {unknown} expected value (remember to check for negation)
|
|
118
|
+
* @param {unknown} actual (optional) will default to `this.obj`
|
|
119
|
+
* @param {boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
|
|
124
|
+
var ok = util.test(this, arguments);
|
|
125
|
+
if (false !== showDiff) showDiff = true;
|
|
126
|
+
if (undefined === expected && undefined === _actual) showDiff = false;
|
|
127
|
+
if (true !== config.showDiff) showDiff = false;
|
|
128
|
+
|
|
129
|
+
if (!ok) {
|
|
130
|
+
msg = util.getMessage(this, arguments);
|
|
131
|
+
var actual = util.getActual(this, arguments);
|
|
132
|
+
var assertionErrorObjectProperties = {
|
|
133
|
+
actual: actual
|
|
134
|
+
, expected: expected
|
|
135
|
+
, showDiff: showDiff
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
var operator = util.getOperator(this, arguments);
|
|
139
|
+
if (operator) {
|
|
140
|
+
assertionErrorObjectProperties.operator = operator;
|
|
79
141
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
142
|
+
|
|
143
|
+
throw new AssertionError(
|
|
144
|
+
msg,
|
|
145
|
+
assertionErrorObjectProperties,
|
|
146
|
+
(config.includeStack) ? this.assert : util.flag(this, 'ssfi'));
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* ### ._obj
|
|
152
|
+
*
|
|
153
|
+
* Quick reference to stored `actual` value for plugin developers.
|
|
154
|
+
*
|
|
155
|
+
* @private
|
|
156
|
+
*/
|
|
157
|
+
Object.defineProperty(Assertion.prototype, '_obj',
|
|
158
|
+
{ get: function () {
|
|
159
|
+
return util.flag(this, 'object');
|
|
90
160
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Assertion.addProperty = function (name, fn) {
|
|
94
|
-
util.addProperty(this.prototype, name, fn);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
Assertion.addMethod = function (name, fn) {
|
|
98
|
-
util.addMethod(this.prototype, name, fn);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
|
|
102
|
-
util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
Assertion.overwriteProperty = function (name, fn) {
|
|
106
|
-
util.overwriteProperty(this.prototype, name, fn);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
Assertion.overwriteMethod = function (name, fn) {
|
|
110
|
-
util.overwriteMethod(this.prototype, name, fn);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
|
|
114
|
-
util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* ### .assert(expression, message, negateMessage, expected, actual, showDiff)
|
|
119
|
-
*
|
|
120
|
-
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
|
|
121
|
-
*
|
|
122
|
-
* @name assert
|
|
123
|
-
* @param {Philosophical} expression to be tested
|
|
124
|
-
* @param {String|Function} message or function that returns message to display if expression fails
|
|
125
|
-
* @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
|
|
126
|
-
* @param {Mixed} expected value (remember to check for negation)
|
|
127
|
-
* @param {Mixed} actual (optional) will default to `this.obj`
|
|
128
|
-
* @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
|
|
129
|
-
* @api private
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
|
|
133
|
-
var ok = util.test(this, arguments);
|
|
134
|
-
if (false !== showDiff) showDiff = true;
|
|
135
|
-
if (undefined === expected && undefined === _actual) showDiff = false;
|
|
136
|
-
if (true !== config.showDiff) showDiff = false;
|
|
137
|
-
|
|
138
|
-
if (!ok) {
|
|
139
|
-
msg = util.getMessage(this, arguments);
|
|
140
|
-
var actual = util.getActual(this, arguments);
|
|
141
|
-
var assertionErrorObjectProperties = {
|
|
142
|
-
actual: actual
|
|
143
|
-
, expected: expected
|
|
144
|
-
, showDiff: showDiff
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
var operator = util.getOperator(this, arguments);
|
|
148
|
-
if (operator) {
|
|
149
|
-
assertionErrorObjectProperties.operator = operator;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
throw new AssertionError(
|
|
153
|
-
msg,
|
|
154
|
-
assertionErrorObjectProperties,
|
|
155
|
-
(config.includeStack) ? this.assert : flag(this, 'ssfi'));
|
|
161
|
+
, set: function (val) {
|
|
162
|
+
util.flag(this, 'object', val);
|
|
156
163
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
/*!
|
|
160
|
-
* ### ._obj
|
|
161
|
-
*
|
|
162
|
-
* Quick reference to stored `actual` value for plugin developers.
|
|
163
|
-
*
|
|
164
|
-
* @api private
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
Object.defineProperty(Assertion.prototype, '_obj',
|
|
168
|
-
{ get: function () {
|
|
169
|
-
return flag(this, 'object');
|
|
170
|
-
}
|
|
171
|
-
, set: function (val) {
|
|
172
|
-
flag(this, 'object', val);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
};
|
|
164
|
+
});
|
package/lib/chai/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export const config = {
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* ### config.includeStack
|
|
@@ -9,10 +9,9 @@ module.exports = {
|
|
|
9
9
|
*
|
|
10
10
|
* chai.config.includeStack = true; // enable stack on error
|
|
11
11
|
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @
|
|
12
|
+
* @param {boolean}
|
|
13
|
+
* @public
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
15
|
includeStack: false,
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -24,10 +23,9 @@ module.exports = {
|
|
|
24
23
|
* will be true when the assertion has requested a diff
|
|
25
24
|
* be shown.
|
|
26
25
|
*
|
|
27
|
-
* @param {
|
|
28
|
-
* @
|
|
26
|
+
* @param {boolean}
|
|
27
|
+
* @public
|
|
29
28
|
*/
|
|
30
|
-
|
|
31
29
|
showDiff: true,
|
|
32
30
|
|
|
33
31
|
/**
|
|
@@ -46,10 +44,9 @@ module.exports = {
|
|
|
46
44
|
*
|
|
47
45
|
* chai.config.truncateThreshold = 0; // disable truncating
|
|
48
46
|
*
|
|
49
|
-
* @param {
|
|
50
|
-
* @
|
|
47
|
+
* @param {number}
|
|
48
|
+
* @public
|
|
51
49
|
*/
|
|
52
|
-
|
|
53
50
|
truncateThreshold: 40,
|
|
54
51
|
|
|
55
52
|
/**
|
|
@@ -66,10 +63,9 @@ module.exports = {
|
|
|
66
63
|
* This feature is automatically disabled regardless of this config value
|
|
67
64
|
* in environments that don't support proxies.
|
|
68
65
|
*
|
|
69
|
-
* @param {
|
|
70
|
-
* @
|
|
66
|
+
* @param {boolean}
|
|
67
|
+
* @public
|
|
71
68
|
*/
|
|
72
|
-
|
|
73
69
|
useProxy: true,
|
|
74
70
|
|
|
75
71
|
/**
|
|
@@ -87,8 +83,32 @@ module.exports = {
|
|
|
87
83
|
* chai.config.proxyExcludedKeys = ['then', 'inspect'];
|
|
88
84
|
*
|
|
89
85
|
* @param {Array}
|
|
90
|
-
* @
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON'],
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* ### config.deepEqual
|
|
92
|
+
*
|
|
93
|
+
* User configurable property, defines which a custom function to use for deepEqual
|
|
94
|
+
* comparisons.
|
|
95
|
+
* By default, the function used is the one from the `deep-eql` package without custom comparator.
|
|
96
|
+
*
|
|
97
|
+
* // use a custom comparator
|
|
98
|
+
* chai.config.deepEqual = (expected, actual) => {
|
|
99
|
+
* return chai.util.eql(expected, actual, {
|
|
100
|
+
* comparator: (expected, actual) => {
|
|
101
|
+
* // for non number comparison, use the default behavior
|
|
102
|
+
* if(typeof expected !== 'number') return null;
|
|
103
|
+
* // allow a difference of 10 between compared numbers
|
|
104
|
+
* return typeof actual === 'number' && Math.abs(actual - expected) < 10
|
|
105
|
+
* }
|
|
106
|
+
* })
|
|
107
|
+
* };
|
|
108
|
+
*
|
|
109
|
+
* @param {Function}
|
|
110
|
+
* @public
|
|
91
111
|
*/
|
|
112
|
+
deepEqual: null
|
|
92
113
|
|
|
93
|
-
proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON']
|
|
94
114
|
};
|