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.
Files changed (38) hide show
  1. package/README.md +3 -3
  2. package/chai.js +138 -79
  3. package/eslint.config.js +12 -0
  4. package/lib/chai/assertion.js +28 -28
  5. package/lib/chai/config.js +18 -24
  6. package/lib/chai/core/assertions.js +252 -255
  7. package/lib/chai/interface/assert.js +438 -390
  8. package/lib/chai/interface/expect.js +7 -2
  9. package/lib/chai/interface/should.js +30 -20
  10. package/lib/chai/utils/addChainableMethod.js +5 -6
  11. package/lib/chai/utils/addLengthGuard.js +3 -3
  12. package/lib/chai/utils/addMethod.js +5 -6
  13. package/lib/chai/utils/addProperty.js +5 -6
  14. package/lib/chai/utils/compareByInspect.js +4 -5
  15. package/lib/chai/utils/expectTypes.js +7 -8
  16. package/lib/chai/utils/flag.js +5 -5
  17. package/lib/chai/utils/getActual.js +3 -3
  18. package/lib/chai/utils/getEnumerableProperties.js +2 -3
  19. package/lib/chai/utils/getMessage.js +4 -4
  20. package/lib/chai/utils/getOperator.js +8 -4
  21. package/lib/chai/utils/getOwnEnumerableProperties.js +2 -3
  22. package/lib/chai/utils/getOwnEnumerablePropertySymbols.js +2 -3
  23. package/lib/chai/utils/getProperties.js +5 -3
  24. package/lib/chai/utils/index.js +23 -2
  25. package/lib/chai/utils/inspect.js +5 -4
  26. package/lib/chai/utils/isNaN.js +3 -3
  27. package/lib/chai/utils/isProxyEnabled.js +1 -1
  28. package/lib/chai/utils/objDisplay.js +2 -3
  29. package/lib/chai/utils/overwriteChainableMethod.js +7 -8
  30. package/lib/chai/utils/overwriteMethod.js +10 -11
  31. package/lib/chai/utils/overwriteProperty.js +10 -12
  32. package/lib/chai/utils/proxify.js +9 -9
  33. package/lib/chai/utils/test.js +3 -3
  34. package/lib/chai/utils/transferFlags.js +4 -6
  35. package/lib/chai/utils/type-detect.js +4 -0
  36. package/lib/chai.js +2 -2
  37. package/package.json +6 -3
  38. 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
- * 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);
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 {Object} ctx object whose property is to be overwritten
39
- * @param {String} name of property to overwrite
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
- * @api public
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 {Object} obj
26
- * @param {String} nonChainableMethodName
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} number
109
- * @return {number} min(string distance between strA and strB, cap)
110
- * @api private
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;
@@ -11,12 +11,12 @@ import {flag} from './flag.js';
11
11
  *
12
12
  * Test an object for expression.
13
13
  *
14
- * @param {Object} object (constructed Assertion)
15
- * @param {Arguments} chai.Assertion.prototype.assert arguments
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 {Object} object the object to transfer the flags to; usually a new assertion
24
- * @param {Boolean} includeAll
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
- * @api private
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
 
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @param {unknown} obj
3
+ * @returns {string}
4
+ */
1
5
  export function type(obj) {
2
6
  if (typeof obj === 'undefined') {
3
7
  return 'undefined';
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
- * @api public
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.0",
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.0.0",
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
  }
@@ -5,7 +5,10 @@ const commonjs = fromRollup(rollupCommonjs);
5
5
 
6
6
  export default {
7
7
  nodeResolve: true,
8
- files: ["test/*.js"],
8
+ files: [
9
+ "test/*.js",
10
+ "!test/virtual-machines.js"
11
+ ],
9
12
  plugins: [
10
13
  commonjs({
11
14
  include: [