@vitest/expect 0.27.1 → 0.27.3

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 +11 -12
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1236,7 +1236,6 @@ Number of calls: ${c.bold(spy.mock.calls.length)}
1236
1236
  });
1237
1237
  };
1238
1238
 
1239
- const isAsyncFunction = (fn) => typeof fn === "function" && fn[Symbol.toStringTag] === "AsyncFunction";
1240
1239
  const getMatcherState = (assertion, expect) => {
1241
1240
  const obj = assertion._obj;
1242
1241
  const isNot = util.flag(assertion, "negate");
@@ -1270,21 +1269,21 @@ class JestExtendError extends Error {
1270
1269
  function JestExtendPlugin(expect, matchers) {
1271
1270
  return (c, utils) => {
1272
1271
  Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
1273
- function expectSyncWrapper(...args) {
1272
+ function expectWrapper(...args) {
1274
1273
  const { state, isNot, obj } = getMatcherState(this, expect);
1275
- const { pass, message, actual, expected } = expectAssertion.call(state, obj, ...args);
1276
- if (pass && isNot || !pass && !isNot)
1277
- throw new JestExtendError(message(), actual, expected);
1278
- }
1279
- async function expectAsyncWrapper(...args) {
1280
- const { state, isNot, obj } = getMatcherState(this, expect);
1281
- const { pass, message, actual, expected } = await expectAssertion.call(state, obj, ...args);
1274
+ const result = expectAssertion.call(state, obj, ...args);
1275
+ if (result && typeof result === "object" && result instanceof Promise) {
1276
+ return result.then(({ pass: pass2, message: message2, actual: actual2, expected: expected2 }) => {
1277
+ if (pass2 && isNot || !pass2 && !isNot)
1278
+ throw new JestExtendError(message2(), actual2, expected2);
1279
+ });
1280
+ }
1281
+ const { pass, message, actual, expected } = result;
1282
1282
  if (pass && isNot || !pass && !isNot)
1283
1283
  throw new JestExtendError(message(), actual, expected);
1284
1284
  }
1285
- const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
1286
- utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, expectAssertionWrapper);
1287
- utils.addMethod(c.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
1285
+ utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, expectWrapper);
1286
+ utils.addMethod(c.Assertion.prototype, expectAssertionName, expectWrapper);
1288
1287
  class CustomMatcher extends AsymmetricMatcher {
1289
1288
  constructor(inverse = false, ...sample) {
1290
1289
  super(sample, inverse);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "0.27.1",
4
+ "version": "0.27.3",
5
5
  "description": "Jest's expect matchers as a Chai plugin",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -26,8 +26,8 @@
26
26
  "dependencies": {
27
27
  "chai": "^4.3.7",
28
28
  "picocolors": "^1.0.0",
29
- "@vitest/spy": "0.27.1",
30
- "@vitest/utils": "0.27.1"
29
+ "@vitest/utils": "0.27.3",
30
+ "@vitest/spy": "0.27.3"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "rimraf dist && rollup -c",