@vitest/expect 4.1.0-beta.5 → 4.1.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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @vitest/expect
2
2
 
3
+ [![NPM version](https://img.shields.io/npm/v/@vitest/runner?color=a1b858&label=)](https://npmx.dev/package/@vitest/runner)
4
+
3
5
  Jest's expect matchers as a Chai plugin.
4
6
 
5
7
  ## Usage
@@ -19,3 +21,5 @@ chai.use(JestChaiExpect)
19
21
  // adds asymmetric matchers like stringContaining, objectContaining
20
22
  chai.use(JestAsymmetricMatchers)
21
23
  ```
24
+
25
+ [GitHub](https://github.com/vitest-dev/vitest/tree/main/packages/expect) | [Documentation](https://vitest.dev/api/expect)
package/dist/index.d.ts CHANGED
@@ -240,8 +240,6 @@ interface AsymmetricMatchersContaining extends CustomMatcher {
240
240
  /**
241
241
  * Matches if the received number is within a certain precision of the expected number.
242
242
  *
243
- * @param precision - Optional decimal precision for comparison. Default is 2.
244
- *
245
243
  * @example
246
244
  * expect(10.45).toEqual(expect.closeTo(10.5, 1));
247
245
  * expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { printDiffOrStringify, diff } from '@vitest/utils/diff';
2
2
  import { stringify } from '@vitest/utils/display';
3
- import { getType, isObject, noop, assertTypes } from '@vitest/utils/helpers';
3
+ import { getType, isObject, noop, assertTypes, ordinal } from '@vitest/utils/helpers';
4
4
  import c from 'tinyrainbow';
5
5
  import { isMockFunction } from '@vitest/spy';
6
6
  import { processError } from '@vitest/utils/error';
@@ -1120,9 +1120,11 @@ function recordAsyncExpect(_test, promise, assertion, error, isSoft) {
1120
1120
  return promise.then(onFulfilled, onRejected);
1121
1121
  },
1122
1122
  catch(onRejected) {
1123
+ resolved = true;
1123
1124
  return promise.catch(onRejected);
1124
1125
  },
1125
1126
  finally(onFinally) {
1127
+ resolved = true;
1126
1128
  return promise.finally(onFinally);
1127
1129
  },
1128
1130
  [Symbol.toStringTag]: "Promise"
@@ -1503,7 +1505,7 @@ const JestChaiExpect = (chai, utils) => {
1503
1505
  const nthCall = spy.mock.calls[times - 1];
1504
1506
  const callCount = spy.mock.calls.length;
1505
1507
  const isCalled = times <= callCount;
1506
- this.assert(nthCall && equalsArgumentArray(nthCall, args), `expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}${isCalled ? `` : `, but called only ${callCount} times`}`, `expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`, args, nthCall, isCalled);
1508
+ this.assert(nthCall && equalsArgumentArray(nthCall, args), `expected ${ordinal(times)} "${spyName}" call to have been called with #{exp}${isCalled ? `` : `, but called only ${callCount} times`}`, `expected ${ordinal(times)} "${spyName}" call to not have been called with #{exp}`, args, nthCall, isCalled);
1507
1509
  });
1508
1510
  def("toHaveBeenLastCalledWith", function(...args) {
1509
1511
  const spy = getSpy(this);
@@ -1688,7 +1690,7 @@ const JestChaiExpect = (chai, utils) => {
1688
1690
  const spyName = spy.getMockName();
1689
1691
  const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1690
1692
  const result = results[nthCall - 1];
1691
- const ordinalCall = `${ordinalOf(nthCall)} call`;
1693
+ const ordinalCall = `${ordinal(nthCall)} call`;
1692
1694
  this.assert(condition(spy, nthCall, value), `expected ${ordinalCall} "${spyName}" call to ${action} #{exp}`, `expected ${ordinalCall} "${spyName}" call to not ${action} #{exp}`, value, result?.value);
1693
1695
  });
1694
1696
  });
@@ -1778,24 +1780,10 @@ const JestChaiExpect = (chai, utils) => {
1778
1780
  return proxy;
1779
1781
  });
1780
1782
  };
1781
- function ordinalOf(i) {
1782
- const j = i % 10;
1783
- const k = i % 100;
1784
- if (j === 1 && k !== 11) {
1785
- return `${i}st`;
1786
- }
1787
- if (j === 2 && k !== 12) {
1788
- return `${i}nd`;
1789
- }
1790
- if (j === 3 && k !== 13) {
1791
- return `${i}rd`;
1792
- }
1793
- return `${i}th`;
1794
- }
1795
1783
  function formatCalls(spy, msg, showActualCall) {
1796
1784
  if (spy.mock.calls.length) {
1797
1785
  msg += c.gray(`\n\nReceived:\n\n${spy.mock.calls.map((callArg, i) => {
1798
- let methodCall = c.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`);
1786
+ let methodCall = c.bold(` ${ordinal(i + 1)} ${spy.getMockName()} call:\n\n`);
1799
1787
  if (showActualCall) {
1800
1788
  methodCall += diff(showActualCall, callArg, { omitAnnotationLines: true });
1801
1789
  } else {
@@ -1811,7 +1799,7 @@ function formatCalls(spy, msg, showActualCall) {
1811
1799
  function formatReturns(spy, results, msg, showActualReturn) {
1812
1800
  if (results.length) {
1813
1801
  msg += c.gray(`\n\nReceived:\n\n${results.map((callReturn, i) => {
1814
- let methodCall = c.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`);
1802
+ let methodCall = c.bold(` ${ordinal(i + 1)} ${spy.getMockName()} call return:\n\n`);
1815
1803
  if (showActualReturn) {
1816
1804
  methodCall += diff(showActualReturn, callReturn.value, { omitAnnotationLines: true });
1817
1805
  } else {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "4.1.0-beta.5",
4
+ "version": "4.1.0",
5
5
  "description": "Jest's expect matchers as a Chai plugin",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
8
- "homepage": "https://github.com/vitest-dev/vitest/tree/main/packages/expect#readme",
8
+ "homepage": "https://vitest.dev/api/expect",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/vitest-dev/vitest.git",
@@ -14,6 +14,12 @@
14
14
  "bugs": {
15
15
  "url": "https://github.com/vitest-dev/vitest/issues"
16
16
  },
17
+ "keywords": [
18
+ "vitest",
19
+ "test",
20
+ "chai",
21
+ "assertion"
22
+ ],
17
23
  "sideEffects": false,
18
24
  "exports": {
19
25
  ".": {
@@ -33,11 +39,11 @@
33
39
  "@types/chai": "^5.2.2",
34
40
  "chai": "^6.2.2",
35
41
  "tinyrainbow": "^3.0.3",
36
- "@vitest/spy": "4.1.0-beta.5",
37
- "@vitest/utils": "4.1.0-beta.5"
42
+ "@vitest/spy": "4.1.0",
43
+ "@vitest/utils": "4.1.0"
38
44
  },
39
45
  "devDependencies": {
40
- "@vitest/runner": "4.1.0-beta.5"
46
+ "@vitest/runner": "4.1.0"
41
47
  },
42
48
  "scripts": {
43
49
  "build": "premove dist && rollup -c",