@vitest/expect 4.1.0-beta.5 → 4.1.0-beta.6

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';
@@ -1503,7 +1503,7 @@ const JestChaiExpect = (chai, utils) => {
1503
1503
  const nthCall = spy.mock.calls[times - 1];
1504
1504
  const callCount = spy.mock.calls.length;
1505
1505
  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);
1506
+ 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
1507
  });
1508
1508
  def("toHaveBeenLastCalledWith", function(...args) {
1509
1509
  const spy = getSpy(this);
@@ -1688,7 +1688,7 @@ const JestChaiExpect = (chai, utils) => {
1688
1688
  const spyName = spy.getMockName();
1689
1689
  const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1690
1690
  const result = results[nthCall - 1];
1691
- const ordinalCall = `${ordinalOf(nthCall)} call`;
1691
+ const ordinalCall = `${ordinal(nthCall)} call`;
1692
1692
  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
1693
  });
1694
1694
  });
@@ -1778,24 +1778,10 @@ const JestChaiExpect = (chai, utils) => {
1778
1778
  return proxy;
1779
1779
  });
1780
1780
  };
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
1781
  function formatCalls(spy, msg, showActualCall) {
1796
1782
  if (spy.mock.calls.length) {
1797
1783
  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`);
1784
+ let methodCall = c.bold(` ${ordinal(i + 1)} ${spy.getMockName()} call:\n\n`);
1799
1785
  if (showActualCall) {
1800
1786
  methodCall += diff(showActualCall, callArg, { omitAnnotationLines: true });
1801
1787
  } else {
@@ -1811,7 +1797,7 @@ function formatCalls(spy, msg, showActualCall) {
1811
1797
  function formatReturns(spy, results, msg, showActualReturn) {
1812
1798
  if (results.length) {
1813
1799
  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`);
1800
+ let methodCall = c.bold(` ${ordinal(i + 1)} ${spy.getMockName()} call return:\n\n`);
1815
1801
  if (showActualReturn) {
1816
1802
  methodCall += diff(showActualReturn, callReturn.value, { omitAnnotationLines: true });
1817
1803
  } 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-beta.6",
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-beta.6",
43
+ "@vitest/utils": "4.1.0-beta.6"
38
44
  },
39
45
  "devDependencies": {
40
- "@vitest/runner": "4.1.0-beta.5"
46
+ "@vitest/runner": "4.1.0-beta.6"
41
47
  },
42
48
  "scripts": {
43
49
  "build": "premove dist && rollup -c",