chai 4.1.0 → 4.3.0
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 +2 -2
- package/LICENSE +1 -1
- package/README.md +6 -6
- package/chai.js +635 -782
- package/index.mjs +13 -0
- package/karma.conf.js +7 -1
- package/karma.sauce.js +1 -1
- package/lib/chai/assertion.js +12 -2
- package/lib/chai/config.js +1 -1
- package/lib/chai/core/assertions.js +267 -162
- package/lib/chai/interface/assert.js +74 -59
- package/lib/chai/interface/expect.js +13 -0
- package/lib/chai/interface/should.js +16 -1
- package/lib/chai/utils/addLengthGuard.js +0 -2
- package/lib/chai/utils/addProperty.js +1 -1
- package/lib/chai/utils/compareByInspect.js +2 -2
- package/lib/chai/utils/getMessage.js +1 -2
- package/lib/chai/utils/getOperator.js +55 -0
- package/lib/chai/utils/getOwnEnumerableProperties.js +1 -1
- package/lib/chai/utils/index.js +6 -0
- package/lib/chai/utils/inspect.js +1 -8
- package/lib/chai/utils/isProxyEnabled.js +1 -1
- package/lib/chai/utils/objDisplay.js +1 -1
- package/lib/chai/utils/overwriteChainableMethod.js +1 -1
- package/lib/chai/utils/overwriteMethod.js +1 -1
- package/lib/chai/utils/overwriteProperty.js +1 -1
- package/lib/chai/utils/proxify.js +54 -32
- package/lib/chai/utils/test.js +1 -1
- package/lib/chai/utils/transferFlags.js +1 -1
- package/lib/chai.js +1 -1
- package/package.json +20 -12
- package/sauce.browsers.js +0 -9
- package/.npmignore +0 -14
|
@@ -18,7 +18,7 @@ var isProxyEnabled = require('./isProxyEnabled');
|
|
|
18
18
|
* the list of existing properties. However, if a nonChainableMethodName is
|
|
19
19
|
* provided, then the root cause is instead a failure to invoke a non-chainable
|
|
20
20
|
* method prior to reading the non-existent property.
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
22
|
* If proxies are unsupported or disabled via the user's Chai config, then
|
|
23
23
|
* return object without modification.
|
|
24
24
|
*
|
|
@@ -49,19 +49,31 @@ module.exports = function proxify(obj, nonChainableMethodName) {
|
|
|
49
49
|
nonChainableMethodName + '".');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
// If the property is reasonably close to an existing Chai property,
|
|
53
|
+
// suggest that property to the user. Only suggest properties with a
|
|
54
|
+
// distance less than 4.
|
|
55
|
+
var suggestion = null;
|
|
56
|
+
var suggestionDistance = 4;
|
|
57
|
+
getProperties(target).forEach(function(prop) {
|
|
58
|
+
if (
|
|
59
|
+
!Object.prototype.hasOwnProperty(prop) &&
|
|
60
|
+
builtins.indexOf(prop) === -1
|
|
61
|
+
) {
|
|
62
|
+
var dist = stringDistanceCapped(
|
|
63
|
+
property,
|
|
64
|
+
prop,
|
|
65
|
+
suggestionDistance
|
|
66
|
+
);
|
|
67
|
+
if (dist < suggestionDistance) {
|
|
68
|
+
suggestion = prop;
|
|
69
|
+
suggestionDistance = dist;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
57
72
|
});
|
|
58
73
|
|
|
59
|
-
if (
|
|
60
|
-
stringDistance(orderedProperties[0], property) < 4) {
|
|
61
|
-
// If the property is reasonably close to an existing Chai property,
|
|
62
|
-
// suggest that property to the user.
|
|
74
|
+
if (suggestion !== null) {
|
|
63
75
|
throw Error('Invalid Chai property: ' + property +
|
|
64
|
-
'. Did you mean "' +
|
|
76
|
+
'. Did you mean "' + suggestion + '"?');
|
|
65
77
|
} else {
|
|
66
78
|
throw Error('Invalid Chai property: ' + property);
|
|
67
79
|
}
|
|
@@ -89,34 +101,44 @@ module.exports = function proxify(obj, nonChainableMethodName) {
|
|
|
89
101
|
};
|
|
90
102
|
|
|
91
103
|
/**
|
|
92
|
-
* #
|
|
93
|
-
* Return the Levenshtein distance between two strings.
|
|
104
|
+
* # stringDistanceCapped(strA, strB, cap)
|
|
105
|
+
* Return the Levenshtein distance between two strings, but no more than cap.
|
|
94
106
|
* @param {string} strA
|
|
95
107
|
* @param {string} strB
|
|
96
|
-
* @
|
|
108
|
+
* @param {number} number
|
|
109
|
+
* @return {number} min(string distance between strA and strB, cap)
|
|
97
110
|
* @api private
|
|
98
111
|
*/
|
|
99
112
|
|
|
100
|
-
function
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
function stringDistanceCapped(strA, strB, cap) {
|
|
114
|
+
if (Math.abs(strA.length - strB.length) >= cap) {
|
|
115
|
+
return cap;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
var memo = [];
|
|
119
|
+
// `memo` is a two-dimensional array containing distances.
|
|
120
|
+
// memo[i][j] is the distance between strA.slice(0, i) and
|
|
121
|
+
// strB.slice(0, j).
|
|
122
|
+
for (var i = 0; i <= strA.length; i++) {
|
|
123
|
+
memo[i] = Array(strB.length + 1).fill(0);
|
|
124
|
+
memo[i][0] = i;
|
|
125
|
+
}
|
|
126
|
+
for (var j = 0; j < strB.length; j++) {
|
|
127
|
+
memo[0][j] = j;
|
|
109
128
|
}
|
|
110
129
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
for (var i = 1; i <= strA.length; i++) {
|
|
131
|
+
var ch = strA.charCodeAt(i - 1);
|
|
132
|
+
for (var j = 1; j <= strB.length; j++) {
|
|
133
|
+
if (Math.abs(i - j) >= cap) {
|
|
134
|
+
memo[i][j] = cap;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
memo[i][j] = Math.min(
|
|
138
|
+
memo[i - 1][j] + 1,
|
|
139
|
+
memo[i][j - 1] + 1,
|
|
140
|
+
memo[i - 1][j - 1] +
|
|
141
|
+
(ch === strB.charCodeAt(j - 1) ? 0 : 1)
|
|
120
142
|
);
|
|
121
143
|
}
|
|
122
144
|
}
|
package/lib/chai/utils/test.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* var newAssertion = new Assertion();
|
|
17
17
|
* utils.transferFlags(assertion, newAssertion);
|
|
18
18
|
*
|
|
19
|
-
* var
|
|
19
|
+
* var anotherAssertion = new Assertion(myObj);
|
|
20
20
|
* utils.transferFlags(assertion, anotherAssertion, false);
|
|
21
21
|
*
|
|
22
22
|
* @param {Assertion} assertion the assertion to transfer the flags from
|
package/lib/chai.js
CHANGED
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"Veselin Todorov <hi@vesln.com>",
|
|
18
18
|
"John Firebaugh <john.firebaugh@gmail.com>"
|
|
19
19
|
],
|
|
20
|
-
"version": "4.
|
|
20
|
+
"version": "4.3.0",
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
23
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -26,29 +26,37 @@
|
|
|
26
26
|
"url": "https://github.com/chaijs/chai/issues"
|
|
27
27
|
},
|
|
28
28
|
"main": "./index",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"require": "./index.js",
|
|
32
|
+
"import": "./index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./": "./"
|
|
35
|
+
},
|
|
29
36
|
"scripts": {
|
|
30
37
|
"test": "make test"
|
|
31
38
|
},
|
|
32
39
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
40
|
+
"node": ">=8"
|
|
34
41
|
},
|
|
35
42
|
"dependencies": {
|
|
36
|
-
"assertion-error": "^1.0
|
|
37
|
-
"check-error": "^1.0.
|
|
38
|
-
"deep-eql": "^
|
|
43
|
+
"assertion-error": "^1.1.0",
|
|
44
|
+
"check-error": "^1.0.2",
|
|
45
|
+
"deep-eql": "^3.0.1",
|
|
39
46
|
"get-func-name": "^2.0.0",
|
|
40
|
-
"pathval": "^1.
|
|
41
|
-
"type-detect": "^4.0.
|
|
47
|
+
"pathval": "^1.1.0",
|
|
48
|
+
"type-detect": "^4.0.5"
|
|
42
49
|
},
|
|
43
50
|
"devDependencies": {
|
|
44
|
-
"browserify": "^
|
|
51
|
+
"browserify": "^16.2.3",
|
|
45
52
|
"bump-cli": "^1.1.3",
|
|
53
|
+
"codecov": "^3.0.0",
|
|
46
54
|
"istanbul": "^0.4.3",
|
|
47
|
-
"karma": "^
|
|
55
|
+
"karma": "^2.0.0",
|
|
56
|
+
"karma-chrome-launcher": "^2.2.0",
|
|
48
57
|
"karma-firefox-launcher": "^1.0.0",
|
|
49
58
|
"karma-mocha": "^1.0.1",
|
|
50
|
-
"karma-
|
|
51
|
-
"
|
|
52
|
-
"mocha": "^3.0.0"
|
|
59
|
+
"karma-sauce-launcher": "^1.2.0",
|
|
60
|
+
"mocha": "^7.1.2"
|
|
53
61
|
}
|
|
54
62
|
}
|
package/sauce.browsers.js
CHANGED