chai 5.1.0 → 5.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/chai.js +138 -79
- package/eslint.config.js +12 -0
- package/lib/chai/assertion.js +28 -28
- package/lib/chai/config.js +18 -24
- package/lib/chai/core/assertions.js +252 -255
- package/lib/chai/interface/assert.js +438 -390
- package/lib/chai/interface/expect.js +7 -2
- package/lib/chai/interface/should.js +30 -20
- package/lib/chai/utils/addChainableMethod.js +5 -6
- package/lib/chai/utils/addLengthGuard.js +3 -3
- package/lib/chai/utils/addMethod.js +5 -6
- package/lib/chai/utils/addProperty.js +5 -6
- package/lib/chai/utils/compareByInspect.js +4 -5
- package/lib/chai/utils/expectTypes.js +7 -8
- package/lib/chai/utils/flag.js +5 -5
- package/lib/chai/utils/getActual.js +3 -3
- package/lib/chai/utils/getEnumerableProperties.js +2 -3
- package/lib/chai/utils/getMessage.js +4 -4
- package/lib/chai/utils/getOperator.js +8 -4
- package/lib/chai/utils/getOwnEnumerableProperties.js +2 -3
- package/lib/chai/utils/getOwnEnumerablePropertySymbols.js +2 -3
- package/lib/chai/utils/getProperties.js +5 -3
- package/lib/chai/utils/index.js +23 -2
- package/lib/chai/utils/inspect.js +5 -4
- package/lib/chai/utils/isNaN.js +3 -3
- package/lib/chai/utils/isProxyEnabled.js +1 -1
- package/lib/chai/utils/objDisplay.js +2 -3
- package/lib/chai/utils/overwriteChainableMethod.js +7 -8
- package/lib/chai/utils/overwriteMethod.js +10 -11
- package/lib/chai/utils/overwriteProperty.js +10 -12
- package/lib/chai/utils/proxify.js +9 -9
- package/lib/chai/utils/test.js +3 -3
- package/lib/chai/utils/transferFlags.js +4 -6
- package/lib/chai/utils/type-detect.js +4 -0
- package/lib/chai.js +2 -2
- package/package.json +6 -3
- package/web-test-runner.config.js +4 -1
|
@@ -16,17 +16,16 @@ import {transferFlags} from './transferFlags.js';
|
|
|
16
16
|
* access to previous value. Must return function to use as getter.
|
|
17
17
|
*
|
|
18
18
|
* utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* return function () {
|
|
20
|
+
* var obj = utils.flag(this, 'object');
|
|
21
|
+
* if (obj instanceof Foo) {
|
|
22
|
+
* new chai.Assertion(obj.name).to.equal('bar');
|
|
23
|
+
* } else {
|
|
24
|
+
* _super.call(this);
|
|
25
|
+
* }
|
|
25
26
|
* }
|
|
26
|
-
* }
|
|
27
27
|
* });
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
29
|
* Can also be accessed directly from `chai.Assertion`.
|
|
31
30
|
*
|
|
32
31
|
* chai.Assertion.overwriteProperty('foo', fn);
|
|
@@ -35,14 +34,13 @@ import {transferFlags} from './transferFlags.js';
|
|
|
35
34
|
*
|
|
36
35
|
* expect(myFoo).to.be.ok;
|
|
37
36
|
*
|
|
38
|
-
* @param {
|
|
39
|
-
* @param {
|
|
37
|
+
* @param {object} ctx object whose property is to be overwritten
|
|
38
|
+
* @param {string} name of property to overwrite
|
|
40
39
|
* @param {Function} getter function that returns a getter function to be used for name
|
|
41
40
|
* @namespace Utils
|
|
42
41
|
* @name overwriteProperty
|
|
43
|
-
* @
|
|
42
|
+
* @public
|
|
44
43
|
*/
|
|
45
|
-
|
|
46
44
|
export function overwriteProperty(ctx, name, getter) {
|
|
47
45
|
var _get = Object.getOwnPropertyDescriptor(ctx, name)
|
|
48
46
|
, _super = function () {};
|
|
@@ -9,6 +9,8 @@ import {isProxyEnabled} from './isProxyEnabled.js';
|
|
|
9
9
|
* MIT Licensed
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
const builtins = ['__flags', '__methods', '_obj', 'assert'];
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* ### .proxify(object)
|
|
14
16
|
*
|
|
@@ -22,14 +24,12 @@ import {isProxyEnabled} from './isProxyEnabled.js';
|
|
|
22
24
|
* If proxies are unsupported or disabled via the user's Chai config, then
|
|
23
25
|
* return object without modification.
|
|
24
26
|
*
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
27
|
+
* @param {object} obj
|
|
28
|
+
* @param {string} nonChainableMethodName
|
|
29
|
+
* @returns {unknown}
|
|
27
30
|
* @namespace Utils
|
|
28
31
|
* @name proxify
|
|
29
32
|
*/
|
|
30
|
-
|
|
31
|
-
const builtins = ['__flags', '__methods', '_obj', 'assert'];
|
|
32
|
-
|
|
33
33
|
export function proxify(obj ,nonChainableMethodName) {
|
|
34
34
|
if (!isProxyEnabled()) return obj;
|
|
35
35
|
|
|
@@ -103,13 +103,13 @@ export function proxify(obj ,nonChainableMethodName) {
|
|
|
103
103
|
/**
|
|
104
104
|
* # stringDistanceCapped(strA, strB, cap)
|
|
105
105
|
* Return the Levenshtein distance between two strings, but no more than cap.
|
|
106
|
+
*
|
|
106
107
|
* @param {string} strA
|
|
107
108
|
* @param {string} strB
|
|
108
|
-
* @param {number}
|
|
109
|
-
* @
|
|
110
|
-
* @
|
|
109
|
+
* @param {number} cap
|
|
110
|
+
* @returns {number} min(string distance between strA and strB, cap)
|
|
111
|
+
* @private
|
|
111
112
|
*/
|
|
112
|
-
|
|
113
113
|
function stringDistanceCapped(strA, strB, cap) {
|
|
114
114
|
if (Math.abs(strA.length - strB.length) >= cap) {
|
|
115
115
|
return cap;
|
package/lib/chai/utils/test.js
CHANGED
|
@@ -11,12 +11,12 @@ import {flag} from './flag.js';
|
|
|
11
11
|
*
|
|
12
12
|
* Test an object for expression.
|
|
13
13
|
*
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
14
|
+
* @param {object} obj (constructed Assertion)
|
|
15
|
+
* @param {unknown} args
|
|
16
|
+
* @returns {unknown}
|
|
16
17
|
* @namespace Utils
|
|
17
18
|
* @name test
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
20
|
export function test(obj, args) {
|
|
21
21
|
var negate = flag(obj, 'negate')
|
|
22
22
|
, expr = args[0];
|
|
@@ -12,21 +12,19 @@
|
|
|
12
12
|
* assertion flags (namely `object`, `ssfi`, `lockSsfi`,
|
|
13
13
|
* and `message`) will not be transferred.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
15
|
* var newAssertion = new Assertion();
|
|
17
16
|
* utils.transferFlags(assertion, newAssertion);
|
|
18
17
|
*
|
|
19
18
|
* var anotherAssertion = new Assertion(myObj);
|
|
20
19
|
* utils.transferFlags(assertion, anotherAssertion, false);
|
|
21
20
|
*
|
|
22
|
-
* @param {Assertion} assertion the assertion to transfer the flags from
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {
|
|
21
|
+
* @param {import('../assertion.js').Assertion} assertion the assertion to transfer the flags from
|
|
22
|
+
* @param {object} object the object to transfer the flags to; usually a new assertion
|
|
23
|
+
* @param {boolean} includeAll
|
|
25
24
|
* @namespace Utils
|
|
26
25
|
* @name transferFlags
|
|
27
|
-
* @
|
|
26
|
+
* @private
|
|
28
27
|
*/
|
|
29
|
-
|
|
30
28
|
export function transferFlags(assertion, object, includeAll) {
|
|
31
29
|
var flags = assertion.__flags || (assertion.__flags = Object.create(null));
|
|
32
30
|
|
package/lib/chai.js
CHANGED
|
@@ -23,9 +23,9 @@ export {AssertionError};
|
|
|
23
23
|
*
|
|
24
24
|
* Provides a way to extend the internals of Chai.
|
|
25
25
|
*
|
|
26
|
-
* @param {Function}
|
|
26
|
+
* @param {Function} fn
|
|
27
27
|
* @returns {this} for chaining
|
|
28
|
-
* @
|
|
28
|
+
* @public
|
|
29
29
|
*/
|
|
30
30
|
export function use(fn) {
|
|
31
31
|
const exports = {
|
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.1.
|
|
21
|
+
"version": "5.1.2",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
24
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -31,10 +31,11 @@
|
|
|
31
31
|
"prebuild": "npm run clean",
|
|
32
32
|
"build": "npm run build:esm",
|
|
33
33
|
"build:esm": "esbuild --bundle --format=esm --keep-names --outfile=chai.js index.js",
|
|
34
|
-
"pretest": "npm run build",
|
|
34
|
+
"pretest": "npm run lint && npm run build",
|
|
35
35
|
"test": "npm run test-node && npm run test-chrome",
|
|
36
36
|
"test-node": "mocha --require ./test/bootstrap/index.js --reporter dot test/*.js",
|
|
37
37
|
"test-chrome": "web-test-runner --playwright",
|
|
38
|
+
"lint": "eslint lib/",
|
|
38
39
|
"clean": "rm -f chai.js coverage"
|
|
39
40
|
},
|
|
40
41
|
"engines": {
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"assertion-error": "^2.0.1",
|
|
45
|
-
"check-error": "^2.
|
|
46
|
+
"check-error": "^2.1.1",
|
|
46
47
|
"deep-eql": "^5.0.1",
|
|
47
48
|
"loupe": "^3.1.0",
|
|
48
49
|
"pathval": "^2.0.0"
|
|
@@ -53,6 +54,8 @@
|
|
|
53
54
|
"@web/test-runner": "^0.18.0",
|
|
54
55
|
"@web/test-runner-playwright": "^0.11.0",
|
|
55
56
|
"esbuild": "^0.19.10",
|
|
57
|
+
"eslint": "^8.56.0",
|
|
58
|
+
"eslint-plugin-jsdoc": "^48.0.4",
|
|
56
59
|
"mocha": "^10.2.0"
|
|
57
60
|
}
|
|
58
61
|
}
|