@vitest/expect 1.6.0 → 2.0.0-beta.10

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
@@ -65,6 +65,7 @@ interface MatcherState {
65
65
  subsetEquality: Tester;
66
66
  };
67
67
  soft?: boolean;
68
+ poll?: boolean;
68
69
  }
69
70
  interface SyncExpectationResult {
70
71
  pass: boolean;
@@ -80,12 +81,7 @@ interface RawMatcherFn<T extends MatcherState = MatcherState> {
80
81
  type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
81
82
  interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
82
83
  <T>(actual: T, message?: string): Assertion<T>;
83
- unreachable: (message?: string) => never;
84
- soft: <T>(actual: T, message?: string) => Assertion<T>;
85
84
  extend: (expects: MatchersObject) => void;
86
- addEqualityTesters: (testers: Array<Tester>) => void;
87
- assertions: (expected: number) => void;
88
- hasAssertions: () => void;
89
85
  anything: () => any;
90
86
  any: (constructor: unknown) => any;
91
87
  getState: () => MatcherState;
@@ -150,12 +146,18 @@ type VitestAssertion<A, T> = {
150
146
  type Promisify<O> = {
151
147
  [K in keyof O]: O[K] extends (...args: infer A) => infer R ? O extends R ? Promisify<O[K]> : (...args: A) => Promise<R> : O[K];
152
148
  };
149
+ type PromisifyAssertion<T> = Promisify<Assertion<T>>;
153
150
  interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T> {
154
151
  toBeTypeOf: (expected: 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined') => void;
155
152
  toHaveBeenCalledOnce: () => void;
156
153
  toSatisfy: <E>(matcher: (value: E) => boolean, message?: string) => void;
157
- resolves: Promisify<Assertion<T>>;
158
- rejects: Promisify<Assertion<T>>;
154
+ toHaveResolved: () => void;
155
+ toHaveResolvedWith: <E>(value: E) => void;
156
+ toHaveResolvedTimes: (times: number) => void;
157
+ toHaveLastResolvedWith: <E>(value: E) => void;
158
+ toHaveNthResolvedWith: <E>(nthCall: number, value: E) => void;
159
+ resolves: PromisifyAssertion<T>;
160
+ rejects: PromisifyAssertion<T>;
159
161
  }
160
162
  declare global {
161
163
  namespace jest {
@@ -255,4 +257,4 @@ declare const JestChaiExpect: ChaiPlugin;
255
257
 
256
258
  declare const JestExtend: ChaiPlugin;
257
259
 
258
- export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, type Assertion, AsymmetricMatcher, type AsymmetricMatcherInterface, type AsymmetricMatchersContaining, type AsyncExpectationResult, type ChaiPlugin, type ExpectStatic, type ExpectationResult, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, type JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, type MatcherHintOptions, type MatcherState, type MatchersObject, ObjectContaining, type RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, type TesterContext, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
260
+ export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, type Assertion, AsymmetricMatcher, type AsymmetricMatcherInterface, type AsymmetricMatchersContaining, type AsyncExpectationResult, type ChaiPlugin, type ExpectStatic, type ExpectationResult, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, type JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, type MatcherHintOptions, type MatcherState, type MatchersObject, ObjectContaining, type PromisifyAssertion, type RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, type TesterContext, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { setupColors } from '@vitest/utils';
3
3
  import { diff } from '@vitest/utils/diff';
4
4
  import { isMockFunction } from '@vitest/spy';
5
5
  import { processError } from '@vitest/utils/error';
6
- import { util } from 'chai';
6
+ import { use, util } from 'chai';
7
7
 
8
8
  const MATCHERS_OBJECT = Symbol.for("matchers-object");
9
9
  const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
@@ -254,7 +254,7 @@ function isDomNode(obj) {
254
254
  function fnNameFor(func) {
255
255
  if (func.name)
256
256
  return func.name;
257
- const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
257
+ const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*(?:\*\s*)?([\w$]+)\s*\(/);
258
258
  return matches ? matches[1] : "<anonymous>";
259
259
  }
260
260
  function getPrototype(obj) {
@@ -273,20 +273,42 @@ function hasProperty(obj, property) {
273
273
  }
274
274
  const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
275
275
  const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
276
+ const IS_LIST_SENTINEL = "@@__IMMUTABLE_LIST__@@";
276
277
  const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
278
+ const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
277
279
  function isImmutableUnorderedKeyed(maybeKeyed) {
278
280
  return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL] && !maybeKeyed[IS_ORDERED_SENTINEL]);
279
281
  }
280
282
  function isImmutableUnorderedSet(maybeSet) {
281
283
  return !!(maybeSet && maybeSet[IS_SET_SENTINEL] && !maybeSet[IS_ORDERED_SENTINEL]);
282
284
  }
285
+ function isObjectLiteral(source) {
286
+ return source != null && typeof source === "object" && !Array.isArray(source);
287
+ }
288
+ function isImmutableList(source) {
289
+ return Boolean(source && isObjectLiteral(source) && source[IS_LIST_SENTINEL]);
290
+ }
291
+ function isImmutableOrderedKeyed(source) {
292
+ return Boolean(
293
+ source && isObjectLiteral(source) && source[IS_KEYED_SENTINEL] && source[IS_ORDERED_SENTINEL]
294
+ );
295
+ }
296
+ function isImmutableOrderedSet(source) {
297
+ return Boolean(
298
+ source && isObjectLiteral(source) && source[IS_SET_SENTINEL] && source[IS_ORDERED_SENTINEL]
299
+ );
300
+ }
301
+ function isImmutableRecord(source) {
302
+ return Boolean(source && isObjectLiteral(source) && source[IS_RECORD_SYMBOL]);
303
+ }
283
304
  const IteratorSymbol = Symbol.iterator;
284
305
  function hasIterator(object) {
285
306
  return !!(object != null && object[IteratorSymbol]);
286
307
  }
287
308
  function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
288
- if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b))
309
+ if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b)) {
289
310
  return void 0;
311
+ }
290
312
  if (a.constructor !== b.constructor)
291
313
  return false;
292
314
  let length = aStack.length;
@@ -358,15 +380,18 @@ function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
358
380
  const bIterator = b[IteratorSymbol]();
359
381
  for (const aValue of a) {
360
382
  const nextB = bIterator.next();
361
- if (nextB.done || !equals(aValue, nextB.value, filteredCustomTesters))
383
+ if (nextB.done || !equals(aValue, nextB.value, filteredCustomTesters)) {
362
384
  return false;
385
+ }
363
386
  }
364
387
  if (!bIterator.next().done)
365
388
  return false;
366
- const aEntries = Object.entries(a);
367
- const bEntries = Object.entries(b);
368
- if (!equals(aEntries, bEntries))
369
- return false;
389
+ if (!isImmutableList(a) && !isImmutableOrderedKeyed(a) && !isImmutableOrderedSet(a) && !isImmutableRecord(a)) {
390
+ const aEntries = Object.entries(a);
391
+ const bEntries = Object.entries(b);
392
+ if (!equals(aEntries, bEntries))
393
+ return false;
394
+ }
370
395
  aStack.pop();
371
396
  bStack.pop();
372
397
  return true;
@@ -638,7 +663,7 @@ class Any extends AsymmetricMatcher {
638
663
  if (func.name)
639
664
  return func.name;
640
665
  const functionToString = Function.prototype.toString;
641
- const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
666
+ const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*(?:\*\s*)?([\w$]+)\s*\(/);
642
667
  return matches ? matches[1] : "<anonymous>";
643
668
  }
644
669
  asymmetricMatch(other) {
@@ -794,10 +819,9 @@ function recordAsyncExpect(test, promise) {
794
819
  function wrapSoft(utils, fn) {
795
820
  return function(...args) {
796
821
  var _a;
797
- const test = utils.flag(this, "vitest-test");
798
- const state = (test == null ? void 0 : test.context._local) ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
799
- if (!state.soft)
822
+ if (!utils.flag(this, "soft"))
800
823
  return fn.apply(this, args);
824
+ const test = utils.flag(this, "vitest-test");
801
825
  if (!test)
802
826
  throw new Error("expect.soft() can only be used inside a test");
803
827
  try {
@@ -1182,7 +1206,7 @@ const JestChaiExpect = (chai, utils) => {
1182
1206
  return `${i}rd`;
1183
1207
  return `${i}th`;
1184
1208
  };
1185
- const formatCalls = (spy, msg, actualCall) => {
1209
+ const formatCalls = (spy, msg, showActualCall) => {
1186
1210
  if (spy.mock.calls) {
1187
1211
  msg += c().gray(`
1188
1212
 
@@ -1192,8 +1216,8 @@ ${spy.mock.calls.map((callArg, i) => {
1192
1216
  let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
1193
1217
 
1194
1218
  `);
1195
- if (actualCall)
1196
- methodCall += diff(actualCall, callArg, { omitAnnotationLines: true });
1219
+ if (showActualCall)
1220
+ methodCall += diff(showActualCall, callArg, { omitAnnotationLines: true });
1197
1221
  else
1198
1222
  methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
1199
1223
  methodCall += "\n";
@@ -1206,17 +1230,17 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1206
1230
  `);
1207
1231
  return msg;
1208
1232
  };
1209
- const formatReturns = (spy, msg, actualReturn) => {
1233
+ const formatReturns = (spy, results, msg, showActualReturn) => {
1210
1234
  msg += c().gray(`
1211
1235
 
1212
1236
  Received:
1213
1237
 
1214
- ${spy.mock.results.map((callReturn, i) => {
1238
+ ${results.map((callReturn, i) => {
1215
1239
  let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
1216
1240
 
1217
1241
  `);
1218
- if (actualReturn)
1219
- methodCall += diff(actualReturn, callReturn.value, { omitAnnotationLines: true });
1242
+ if (showActualReturn)
1243
+ methodCall += diff(showActualReturn, callReturn.value, { omitAnnotationLines: true });
1220
1244
  else
1221
1245
  methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
1222
1246
  methodCall += "\n";
@@ -1385,88 +1409,171 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1385
1409
  }
1386
1410
  throw new Error(`"toThrow" expects string, RegExp, function, Error instance or asymmetric matcher, got "${typeof expected}"`);
1387
1411
  });
1388
- def(["toHaveReturned", "toReturn"], function() {
1389
- const spy = getSpy(this);
1390
- const spyName = spy.getMockName();
1391
- const calledAndNotThrew = spy.mock.calls.length > 0 && spy.mock.results.some(({ type }) => type !== "throw");
1392
- this.assert(
1393
- calledAndNotThrew,
1394
- `expected "${spyName}" to be successfully called at least once`,
1395
- `expected "${spyName}" to not be successfully called`,
1396
- calledAndNotThrew,
1397
- !calledAndNotThrew,
1398
- false
1399
- );
1400
- });
1401
- def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
1402
- const spy = getSpy(this);
1403
- const spyName = spy.getMockName();
1404
- const successfulReturns = spy.mock.results.reduce((success, { type }) => type === "throw" ? success : ++success, 0);
1405
- this.assert(
1406
- successfulReturns === times,
1407
- `expected "${spyName}" to be successfully called ${times} times`,
1408
- `expected "${spyName}" to not be successfully called ${times} times`,
1409
- `expected number of returns: ${times}`,
1410
- `received number of returns: ${successfulReturns}`,
1411
- false
1412
- );
1412
+ [
1413
+ {
1414
+ name: "toHaveResolved",
1415
+ condition: (spy) => spy.mock.settledResults.length > 0 && spy.mock.settledResults.some(({ type }) => type === "fulfilled"),
1416
+ action: "resolved"
1417
+ },
1418
+ {
1419
+ name: ["toHaveReturned", "toReturn"],
1420
+ condition: (spy) => spy.mock.calls.length > 0 && spy.mock.results.some(({ type }) => type !== "throw"),
1421
+ action: "called"
1422
+ }
1423
+ ].forEach(({ name, condition, action }) => {
1424
+ def(name, function() {
1425
+ const spy = getSpy(this);
1426
+ const spyName = spy.getMockName();
1427
+ const pass = condition(spy);
1428
+ this.assert(
1429
+ pass,
1430
+ `expected "${spyName}" to be successfully ${action} at least once`,
1431
+ `expected "${spyName}" to not be successfully ${action}`,
1432
+ pass,
1433
+ !pass,
1434
+ false
1435
+ );
1436
+ });
1413
1437
  });
1414
- def(["toHaveReturnedWith", "toReturnWith"], function(value) {
1415
- const spy = getSpy(this);
1416
- const spyName = spy.getMockName();
1417
- const pass = spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result));
1418
- const isNot = utils.flag(this, "negate");
1419
- const msg = utils.getMessage(
1420
- this,
1421
- [
1438
+ [
1439
+ {
1440
+ name: "toHaveResolvedTimes",
1441
+ condition: (spy, times) => spy.mock.settledResults.reduce((s, { type }) => type === "fulfilled" ? ++s : s, 0) === times,
1442
+ action: "resolved"
1443
+ },
1444
+ {
1445
+ name: ["toHaveReturnedTimes", "toReturnTimes"],
1446
+ condition: (spy, times) => spy.mock.results.reduce((s, { type }) => type === "throw" ? s : ++s, 0) === times,
1447
+ action: "called"
1448
+ }
1449
+ ].forEach(({ name, condition, action }) => {
1450
+ def(name, function(times) {
1451
+ const spy = getSpy(this);
1452
+ const spyName = spy.getMockName();
1453
+ const pass = condition(spy, times);
1454
+ this.assert(
1422
1455
  pass,
1423
- `expected "${spyName}" to return with: #{exp} at least once`,
1424
- `expected "${spyName}" to not return with: #{exp}`,
1425
- value
1426
- ]
1427
- );
1428
- if (pass && isNot || !pass && !isNot)
1429
- throw new AssertionError(formatReturns(spy, msg, value));
1456
+ `expected "${spyName}" to be successfully ${action} ${times} times`,
1457
+ `expected "${spyName}" to not be successfully ${action} ${times} times`,
1458
+ `expected resolved times: ${times}`,
1459
+ `received resolved times: ${pass}`,
1460
+ false
1461
+ );
1462
+ });
1430
1463
  });
1431
- def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
1432
- const spy = getSpy(this);
1433
- const spyName = spy.getMockName();
1434
- const { value: lastResult } = spy.mock.results[spy.mock.results.length - 1];
1435
- const pass = equals(lastResult, value);
1436
- this.assert(
1437
- pass,
1438
- `expected last "${spyName}" call to return #{exp}`,
1439
- `expected last "${spyName}" call to not return #{exp}`,
1440
- value,
1441
- lastResult
1442
- );
1464
+ [
1465
+ {
1466
+ name: "toHaveResolvedWith",
1467
+ condition: (spy, value) => spy.mock.settledResults.some(({ type, value: result }) => type === "fulfilled" && equals(value, result)),
1468
+ action: "resolve"
1469
+ },
1470
+ {
1471
+ name: ["toHaveReturnedWith", "toReturnWith"],
1472
+ condition: (spy, value) => spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result)),
1473
+ action: "return"
1474
+ }
1475
+ ].forEach(({ name, condition, action }) => {
1476
+ def(name, function(value) {
1477
+ const spy = getSpy(this);
1478
+ const pass = condition(spy, value);
1479
+ const isNot = utils.flag(this, "negate");
1480
+ if (pass && isNot || !pass && !isNot) {
1481
+ const spyName = spy.getMockName();
1482
+ const msg = utils.getMessage(
1483
+ this,
1484
+ [
1485
+ pass,
1486
+ `expected "${spyName}" to ${action} with: #{exp} at least once`,
1487
+ `expected "${spyName}" to not ${action} with: #{exp}`,
1488
+ value
1489
+ ]
1490
+ );
1491
+ const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1492
+ throw new AssertionError(formatReturns(spy, results, msg, value));
1493
+ }
1494
+ });
1443
1495
  });
1444
- def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
1445
- const spy = getSpy(this);
1446
- const spyName = spy.getMockName();
1447
- const isNot = utils.flag(this, "negate");
1448
- const { type: callType, value: callResult } = spy.mock.results[nthCall - 1];
1449
- const ordinalCall = `${ordinalOf(nthCall)} call`;
1450
- if (!isNot && callType === "throw")
1451
- chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
1452
- const nthCallReturn = equals(callResult, value);
1453
- this.assert(
1454
- nthCallReturn,
1455
- `expected ${ordinalCall} "${spyName}" call to return #{exp}`,
1456
- `expected ${ordinalCall} "${spyName}" call to not return #{exp}`,
1457
- value,
1458
- callResult
1459
- );
1496
+ [
1497
+ {
1498
+ name: "toHaveLastResolvedWith",
1499
+ condition: (spy, value) => {
1500
+ const result = spy.mock.settledResults[spy.mock.settledResults.length - 1];
1501
+ return result && result.type === "fulfilled" && equals(result.value, value);
1502
+ },
1503
+ action: "resolve"
1504
+ },
1505
+ {
1506
+ name: ["toHaveLastReturnedWith", "lastReturnedWith"],
1507
+ condition: (spy, value) => {
1508
+ const result = spy.mock.results[spy.mock.results.length - 1];
1509
+ return result && result.type === "return" && equals(result.value, value);
1510
+ },
1511
+ action: "return"
1512
+ }
1513
+ ].forEach(({ name, condition, action }) => {
1514
+ def(name, function(value) {
1515
+ const spy = getSpy(this);
1516
+ const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1517
+ const result = results[results.length - 1];
1518
+ const spyName = spy.getMockName();
1519
+ this.assert(
1520
+ condition(spy, value),
1521
+ `expected last "${spyName}" call to ${action} #{exp}`,
1522
+ `expected last "${spyName}" call to not ${action} #{exp}`,
1523
+ value,
1524
+ result == null ? void 0 : result.value
1525
+ );
1526
+ });
1527
+ });
1528
+ [
1529
+ {
1530
+ name: "toHaveNthResolvedWith",
1531
+ condition: (spy, index, value) => {
1532
+ const result = spy.mock.settledResults[index - 1];
1533
+ return result && result.type === "fulfilled" && equals(result.value, value);
1534
+ },
1535
+ action: "resolve"
1536
+ },
1537
+ {
1538
+ name: ["toHaveNthReturnedWith", "nthReturnedWith"],
1539
+ condition: (spy, index, value) => {
1540
+ const result = spy.mock.results[index - 1];
1541
+ return result && result.type === "return" && equals(result.value, value);
1542
+ },
1543
+ action: "return"
1544
+ }
1545
+ ].forEach(({ name, condition, action }) => {
1546
+ def(name, function(nthCall, value) {
1547
+ const spy = getSpy(this);
1548
+ const spyName = spy.getMockName();
1549
+ const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1550
+ const result = results[nthCall - 1];
1551
+ const ordinalCall = `${ordinalOf(nthCall)} call`;
1552
+ this.assert(
1553
+ condition(spy, nthCall, value),
1554
+ `expected ${ordinalCall} "${spyName}" call to ${action} #{exp}`,
1555
+ `expected ${ordinalCall} "${spyName}" call to not ${action} #{exp}`,
1556
+ value,
1557
+ result == null ? void 0 : result.value
1558
+ );
1559
+ });
1460
1560
  });
1461
1561
  def("toSatisfy", function(matcher, message) {
1462
1562
  return this.be.satisfy(matcher, message);
1463
1563
  });
1564
+ def("withContext", function(context) {
1565
+ for (const key in context)
1566
+ utils.flag(this, key, context[key]);
1567
+ return this;
1568
+ });
1464
1569
  utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() {
1465
1570
  const error = new Error("resolves");
1466
1571
  utils.flag(this, "promise", "resolves");
1467
1572
  utils.flag(this, "error", error);
1468
1573
  const test = utils.flag(this, "vitest-test");
1469
1574
  const obj = utils.flag(this, "object");
1575
+ if (utils.flag(this, "poll"))
1576
+ throw new SyntaxError(`expect.poll() is not supported in combination with .resolves`);
1470
1577
  if (typeof (obj == null ? void 0 : obj.then) !== "function")
1471
1578
  throw new TypeError(`You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`);
1472
1579
  const proxy = new Proxy(this, {
@@ -1503,6 +1610,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1503
1610
  const test = utils.flag(this, "vitest-test");
1504
1611
  const obj = utils.flag(this, "object");
1505
1612
  const wrapper = typeof obj === "function" ? obj() : obj;
1613
+ if (utils.flag(this, "poll"))
1614
+ throw new SyntaxError(`expect.poll() is not supported in combination with .rejects`);
1506
1615
  if (typeof (wrapper == null ? void 0 : wrapper.then) !== "function")
1507
1616
  throw new TypeError(`You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`);
1508
1617
  const proxy = new Proxy(this, {
@@ -1552,7 +1661,9 @@ function getMatcherState(assertion, expect) {
1552
1661
  promise,
1553
1662
  equals,
1554
1663
  // needed for built-in jest-snapshots, but we don't use it
1555
- suppressedErrors: []
1664
+ suppressedErrors: [],
1665
+ soft: util.flag(assertion, "soft"),
1666
+ poll: util.flag(assertion, "poll")
1556
1667
  };
1557
1668
  return {
1558
1669
  state: matcherState,
@@ -1567,8 +1678,8 @@ class JestExtendError extends Error {
1567
1678
  this.expected = expected;
1568
1679
  }
1569
1680
  }
1570
- function JestExtendPlugin(expect, matchers) {
1571
- return (c, utils) => {
1681
+ function JestExtendPlugin(c, expect, matchers) {
1682
+ return (_, utils) => {
1572
1683
  Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
1573
1684
  function expectWrapper(...args) {
1574
1685
  const { state, isNot, obj } = getMatcherState(this, expect);
@@ -1632,7 +1743,7 @@ function JestExtendPlugin(expect, matchers) {
1632
1743
  }
1633
1744
  const JestExtend = (chai, utils) => {
1634
1745
  utils.addMethod(chai.expect, "extend", (expect, expects) => {
1635
- chai.use(JestExtendPlugin(expect, expects));
1746
+ use(JestExtendPlugin(chai, expect, expects));
1636
1747
  });
1637
1748
  };
1638
1749
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "1.6.0",
4
+ "version": "2.0.0-beta.10",
5
5
  "description": "Jest's expect matchers as a Chai plugin",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -30,15 +30,15 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "chai": "^4.3.10",
34
- "@vitest/utils": "1.6.0",
35
- "@vitest/spy": "1.6.0"
33
+ "chai": "^5.1.1",
34
+ "@vitest/spy": "2.0.0-beta.10",
35
+ "@vitest/utils": "2.0.0-beta.10"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/chai": "4.3.6",
39
- "picocolors": "^1.0.0",
39
+ "picocolors": "^1.0.1",
40
40
  "rollup-plugin-copy": "^3.5.0",
41
- "@vitest/runner": "1.6.0"
41
+ "@vitest/runner": "2.0.0-beta.10"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rimraf dist && rollup -c",