@vitest/expect 3.2.2 → 3.2.4

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/dist/index.d.ts CHANGED
@@ -165,8 +165,8 @@ type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawM
165
165
  interface ExpectStatic extends Chai.ExpectStatic, Matchers, AsymmetricMatchersContaining {
166
166
  <T>(actual: T, message?: string): Assertion<T>;
167
167
  extend: (expects: MatchersObject) => void;
168
- anything: () => AsymmetricMatcher<unknown>;
169
- any: (constructor: unknown) => AsymmetricMatcher<unknown>;
168
+ anything: () => any;
169
+ any: (constructor: unknown) => any;
170
170
  getState: () => MatcherState;
171
171
  setState: (state: Partial<MatcherState>) => void;
172
172
  not: AsymmetricMatchersContaining;
@@ -245,14 +245,14 @@ interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
245
245
  * @example
246
246
  * expect(user).toEqual({ name: 'Alice', age: 30 });
247
247
  */
248
- toEqual: <E>(expected: DeeplyAllowMatchers<E>) => void;
248
+ toEqual: <E>(expected: E) => void;
249
249
  /**
250
250
  * Use to test that objects have the same types as well as structure.
251
251
  *
252
252
  * @example
253
253
  * expect(user).toStrictEqual({ name: 'Alice', age: 30 });
254
254
  */
255
- toStrictEqual: <E>(expected: DeeplyAllowMatchers<E>) => void;
255
+ toStrictEqual: <E>(expected: E) => void;
256
256
  /**
257
257
  * Checks that a value is what you expect. It calls `Object.is` to compare values.
258
258
  * Don't use `toBe` with floating-point numbers.
@@ -279,7 +279,7 @@ interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
279
279
  * address: { city: 'Wonderland' }
280
280
  * });
281
281
  */
282
- toMatchObject: <E extends object | any[]>(expected: DeeplyAllowMatchers<E>) => void;
282
+ toMatchObject: <E extends object | any[]>(expected: E) => void;
283
283
  /**
284
284
  * Used when you want to check that an item is in a list.
285
285
  * For testing the items in the list, this uses `===`, a strict equality check.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getType, stringify, isObject, assertTypes } from '@vitest/utils';
1
+ import { getType, stringify, isObject, noop, assertTypes } from '@vitest/utils';
2
2
  import { printDiffOrStringify, diff } from '@vitest/utils/diff';
3
3
  import c from 'tinyrainbow';
4
4
  import { isMockFunction } from '@vitest/spy';
@@ -1012,6 +1012,13 @@ function recordAsyncExpect(_test, promise, assertion, error) {
1012
1012
  }
1013
1013
  return promise;
1014
1014
  }
1015
+ function handleTestError(test, err) {
1016
+ var _test$result;
1017
+ test.result || (test.result = { state: "fail" });
1018
+ test.result.state = "fail";
1019
+ (_test$result = test.result).errors || (_test$result.errors = []);
1020
+ test.result.errors.push(processError(err));
1021
+ }
1015
1022
  function wrapAssertion(utils, name, fn) {
1016
1023
  return function(...args) {
1017
1024
  // private
@@ -1026,13 +1033,15 @@ function wrapAssertion(utils, name, fn) {
1026
1033
  throw new Error("expect.soft() can only be used inside a test");
1027
1034
  }
1028
1035
  try {
1029
- return fn.apply(this, args);
1036
+ const result = fn.apply(this, args);
1037
+ if (result && typeof result === "object" && typeof result.then === "function") {
1038
+ return result.then(noop, (err) => {
1039
+ handleTestError(test, err);
1040
+ });
1041
+ }
1042
+ return result;
1030
1043
  } catch (err) {
1031
- var _test$result;
1032
- test.result || (test.result = { state: "fail" });
1033
- test.result.state = "fail";
1034
- (_test$result = test.result).errors || (_test$result.errors = []);
1035
- test.result.errors.push(processError(err));
1044
+ handleTestError(test, err);
1036
1045
  }
1037
1046
  };
1038
1047
  }
@@ -1723,8 +1732,9 @@ function JestExtendPlugin(c, expect, matchers) {
1723
1732
  function expectWrapper(...args) {
1724
1733
  const { state, isNot, obj } = getMatcherState(this, expect);
1725
1734
  const result = expectAssertion.call(state, obj, ...args);
1726
- if (result && typeof result === "object" && result instanceof Promise) {
1727
- return result.then(({ pass, message, actual, expected }) => {
1735
+ if (result && typeof result === "object" && typeof result.then === "function") {
1736
+ const thenable = result;
1737
+ return thenable.then(({ pass, message, actual, expected }) => {
1728
1738
  if (pass && isNot || !pass && !isNot) {
1729
1739
  throw new JestExtendError(message(), actual, expected);
1730
1740
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "3.2.2",
4
+ "version": "3.2.4",
5
5
  "description": "Jest's expect matchers as a Chai plugin",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -32,12 +32,12 @@
32
32
  "@types/chai": "^5.2.2",
33
33
  "chai": "^5.2.0",
34
34
  "tinyrainbow": "^2.0.0",
35
- "@vitest/spy": "3.2.2",
36
- "@vitest/utils": "3.2.2"
35
+ "@vitest/spy": "3.2.4",
36
+ "@vitest/utils": "3.2.4"
37
37
  },
38
38
  "devDependencies": {
39
39
  "rollup-plugin-copy": "^3.5.0",
40
- "@vitest/runner": "3.2.2"
40
+ "@vitest/runner": "3.2.4"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "rimraf dist && rollup -c",