@vitest/expect 3.2.3 → 4.0.0-beta.1

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 (2) hide show
  1. package/dist/index.js +19 -9
  2. package/package.json +4 -4
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.3",
4
+ "version": "4.0.0-beta.1",
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.3",
36
- "@vitest/utils": "3.2.3"
35
+ "@vitest/spy": "4.0.0-beta.1",
36
+ "@vitest/utils": "4.0.0-beta.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "rollup-plugin-copy": "^3.5.0",
40
- "@vitest/runner": "3.2.3"
40
+ "@vitest/runner": "4.0.0-beta.1"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "rimraf dist && rollup -c",