@vitest/expect 3.0.5 → 3.0.7

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
@@ -1,6 +1,5 @@
1
1
  import { MockInstance } from '@vitest/spy';
2
2
  import { stringify, Constructable } from '@vitest/utils';
3
- import * as tinyrainbow from 'tinyrainbow';
4
3
  import { Formatter } from 'tinyrainbow';
5
4
  import { diff, printDiffOrStringify } from '@vitest/utils/diff';
6
5
  export { DiffOptions } from '@vitest/utils/diff';
@@ -14,11 +13,11 @@ declare function matcherHint(matcherName: string, received?: string, expected?:
14
13
  declare function printReceived(object: unknown): string;
15
14
  declare function printExpected(value: unknown): string;
16
15
  declare function getMatcherUtils(): {
17
- EXPECTED_COLOR: tinyrainbow.Formatter;
18
- RECEIVED_COLOR: tinyrainbow.Formatter;
19
- INVERTED_COLOR: tinyrainbow.Formatter;
20
- BOLD_WEIGHT: tinyrainbow.Formatter;
21
- DIM_COLOR: tinyrainbow.Formatter;
16
+ EXPECTED_COLOR: Formatter;
17
+ RECEIVED_COLOR: Formatter;
18
+ INVERTED_COLOR: Formatter;
19
+ BOLD_WEIGHT: Formatter;
20
+ DIM_COLOR: Formatter;
22
21
  diff: typeof diff;
23
22
  matcherHint: typeof matcherHint;
24
23
  printReceived: typeof printReceived;
@@ -87,7 +86,7 @@ type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
87
86
  interface RawMatcherFn<T extends MatcherState = MatcherState> {
88
87
  (this: T, received: any, ...expected: Array<any>): ExpectationResult;
89
88
  }
90
- type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
89
+ type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>> & ThisType<T>;
91
90
  interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
92
91
  <T>(actual: T, message?: string): Assertion<T>;
93
92
  extend: (expects: MatchersObject) => void;
@@ -693,7 +692,7 @@ declare class StringContaining extends AsymmetricMatcher<string> {
693
692
  getExpectedType(): string;
694
693
  }
695
694
  declare class Anything extends AsymmetricMatcher<void> {
696
- asymmetricMatch(other: unknown): other is {};
695
+ asymmetricMatch(other: unknown): boolean;
697
696
  toString(): string;
698
697
  toAsymmetricMatcher(): string;
699
698
  }
@@ -733,7 +732,7 @@ declare const JestExtend: ChaiPlugin;
733
732
 
734
733
  declare function equals(a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean): boolean;
735
734
  declare function isAsymmetric(obj: any): boolean;
736
- declare function hasAsymmetric(obj: any, seen?: Set<unknown>): boolean;
735
+ declare function hasAsymmetric(obj: any, seen?: Set<any>): boolean;
737
736
  declare function isA(typeName: string, value: unknown): boolean;
738
737
  declare function fnNameFor(func: Function): string;
739
738
  declare function hasProperty(obj: object | null, property: string): boolean;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getType, stringify, isObject, assertTypes } from '@vitest/utils';
2
- import { diff, printDiffOrStringify } from '@vitest/utils/diff';
2
+ import { printDiffOrStringify, diff } from '@vitest/utils/diff';
3
3
  import c from 'tinyrainbow';
4
4
  import { isMockFunction } from '@vitest/spy';
5
5
  import { processError } from '@vitest/utils/error';
@@ -186,7 +186,7 @@ function asymmetricMatch(a, b) {
186
186
  const asymmetricA = isAsymmetric(a);
187
187
  const asymmetricB = isAsymmetric(b);
188
188
  if (asymmetricA && asymmetricB) {
189
- return undefined;
189
+ return void 0;
190
190
  }
191
191
  if (asymmetricA) {
192
192
  return a.asymmetricMatch(b);
@@ -198,7 +198,7 @@ function asymmetricMatch(a, b) {
198
198
  function eq(a, b, aStack, bStack, customTesters, hasKey2) {
199
199
  let result = true;
200
200
  const asymmetricResult = asymmetricMatch(a, b);
201
- if (asymmetricResult !== undefined) {
201
+ if (asymmetricResult !== void 0) {
202
202
  return asymmetricResult;
203
203
  }
204
204
  const testerContext = { equals };
@@ -209,7 +209,7 @@ function eq(a, b, aStack, bStack, customTesters, hasKey2) {
209
209
  b,
210
210
  customTesters
211
211
  );
212
- if (customTesterResult !== undefined) {
212
+ if (customTesterResult !== void 0) {
213
213
  return customTesterResult;
214
214
  }
215
215
  }
@@ -315,7 +315,7 @@ function keys(obj, hasKey2) {
315
315
  );
316
316
  }
317
317
  function hasDefinedKey(obj, key) {
318
- return hasKey(obj, key) && obj[key] !== undefined;
318
+ return hasKey(obj, key) && obj[key] !== void 0;
319
319
  }
320
320
  function hasKey(obj, key) {
321
321
  return Object.prototype.hasOwnProperty.call(obj, key);
@@ -387,7 +387,7 @@ function hasIterator(object) {
387
387
  }
388
388
  function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
389
389
  if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b)) {
390
- return undefined;
390
+ return void 0;
391
391
  }
392
392
  if (a.constructor !== b.constructor) {
393
393
  return false;
@@ -407,7 +407,7 @@ function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
407
407
  function iterableEqualityWithStack(a2, b2) {
408
408
  return iterableEquality(a2, b2, [...customTesters], [...aStack], [...bStack]);
409
409
  }
410
- if (a.size !== undefined) {
410
+ if (a.size !== void 0) {
411
411
  if (a.size !== b.size) {
412
412
  return false;
413
413
  } else if (isA("Set", a) || isImmutableUnorderedSet(a)) {
@@ -501,7 +501,7 @@ function subsetEquality(object, subset, customTesters = []) {
501
501
  );
502
502
  const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
503
503
  if (!isObjectWithKeys(subset2)) {
504
- return undefined;
504
+ return void 0;
505
505
  }
506
506
  return Object.keys(subset2).every((key) => {
507
507
  if (subset2[key] != null && typeof subset2[key] === "object") {
@@ -522,7 +522,7 @@ function subsetEquality(object, subset, customTesters = []) {
522
522
  }
523
523
  function typeEquality(a, b) {
524
524
  if (a == null || b == null || a.constructor === b.constructor) {
525
- return undefined;
525
+ return void 0;
526
526
  }
527
527
  return false;
528
528
  }
@@ -531,13 +531,13 @@ function arrayBufferEquality(a, b) {
531
531
  let dataViewB = b;
532
532
  if (!(a instanceof DataView && b instanceof DataView)) {
533
533
  if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer)) {
534
- return undefined;
534
+ return void 0;
535
535
  }
536
536
  try {
537
537
  dataViewA = new DataView(a);
538
538
  dataViewB = new DataView(b);
539
539
  } catch {
540
- return undefined;
540
+ return void 0;
541
541
  }
542
542
  }
543
543
  if (dataViewA.byteLength !== dataViewB.byteLength) {
@@ -552,7 +552,7 @@ function arrayBufferEquality(a, b) {
552
552
  }
553
553
  function sparseArrayEquality(a, b, customTesters = []) {
554
554
  if (!Array.isArray(a) || !Array.isArray(b)) {
555
- return undefined;
555
+ return void 0;
556
556
  }
557
557
  const aKeys = Object.keys(a);
558
558
  const bKeys = Object.keys(b);
@@ -583,7 +583,7 @@ function getObjectKeys(object) {
583
583
  ...Object.getOwnPropertySymbols(object).filter(
584
584
  (s) => {
585
585
  var _a;
586
- return (_a = Object.getOwnPropertyDescriptor(object, s)) == null ? undefined : _a.enumerable;
586
+ return (_a = Object.getOwnPropertyDescriptor(object, s)) == null ? void 0 : _a.enumerable;
587
587
  }
588
588
  )
589
589
  ];
@@ -698,16 +698,14 @@ class AsymmetricMatcher {
698
698
  }
699
699
  };
700
700
  }
701
- // implement custom chai/loupe inspect for better AssertionError.message formatting
702
- // https://github.com/chaijs/loupe/blob/9b8a6deabcd50adc056a64fb705896194710c5c6/src/index.ts#L29
703
- [Symbol.for("chai/inspect")](options) {
704
- const result = stringify(this, options.depth, { min: true });
705
- if (result.length <= options.truncate) {
706
- return result;
707
- }
708
- return `${this.toString()}{\u2026}`;
709
- }
710
701
  }
702
+ AsymmetricMatcher.prototype[Symbol.for("chai/inspect")] = function(options) {
703
+ const result = stringify(this, options.depth, { min: true });
704
+ if (result.length <= options.truncate) {
705
+ return result;
706
+ }
707
+ return `${this.toString()}{\u2026}`;
708
+ };
711
709
  class StringContaining extends AsymmetricMatcher {
712
710
  constructor(sample, inverse = false) {
713
711
  if (!isA("String", sample)) {
@@ -1001,7 +999,7 @@ function recordAsyncExpect(_test, promise, assertion, error) {
1001
999
  test.onFinished.push(() => {
1002
1000
  var _a;
1003
1001
  if (!resolved) {
1004
- const processor = ((_a = globalThis.__vitest_worker__) == null ? undefined : _a.onFilterStackTrace) || ((s) => s || "");
1002
+ const processor = ((_a = globalThis.__vitest_worker__) == null ? void 0 : _a.onFilterStackTrace) || ((s) => s || "");
1005
1003
  const stack = processor(error.stack);
1006
1004
  console.warn([
1007
1005
  `Promise returned by \`${assertion}\` was not awaited. `,
@@ -1357,10 +1355,10 @@ const JestChaiExpect = (chai, utils) => {
1357
1355
  def("toBeUndefined", function() {
1358
1356
  const obj = utils.flag(this, "object");
1359
1357
  this.assert(
1360
- undefined === obj,
1358
+ void 0 === obj,
1361
1359
  "expected #{this} to be undefined",
1362
1360
  "expected #{this} not to be undefined",
1363
- undefined,
1361
+ void 0,
1364
1362
  obj
1365
1363
  );
1366
1364
  });
@@ -1429,7 +1427,7 @@ const JestChaiExpect = (chai, utils) => {
1429
1427
  `expected #{this} to have property "${propertyName}"${valueString}`,
1430
1428
  `expected #{this} to not have property "${propertyName}"${valueString}`,
1431
1429
  expected,
1432
- exists ? value : undefined
1430
+ exists ? value : void 0
1433
1431
  );
1434
1432
  }
1435
1433
  );
@@ -1836,7 +1834,7 @@ const JestChaiExpect = (chai, utils) => {
1836
1834
  `expected last "${spyName}" call to ${action} #{exp}`,
1837
1835
  `expected last "${spyName}" call to not ${action} #{exp}`,
1838
1836
  value,
1839
- result == null ? undefined : result.value
1837
+ result == null ? void 0 : result.value
1840
1838
  );
1841
1839
  });
1842
1840
  });
@@ -1869,7 +1867,7 @@ const JestChaiExpect = (chai, utils) => {
1869
1867
  `expected ${ordinalCall} "${spyName}" call to ${action} #{exp}`,
1870
1868
  `expected ${ordinalCall} "${spyName}" call to not ${action} #{exp}`,
1871
1869
  value,
1872
- result == null ? undefined : result.value
1870
+ result == null ? void 0 : result.value
1873
1871
  );
1874
1872
  });
1875
1873
  });
@@ -1893,7 +1891,7 @@ const JestChaiExpect = (chai, utils) => {
1893
1891
  `expect.poll() is not supported in combination with .resolves`
1894
1892
  );
1895
1893
  }
1896
- if (typeof (obj == null ? undefined : obj.then) !== "function") {
1894
+ if (typeof (obj == null ? void 0 : obj.then) !== "function") {
1897
1895
  throw new TypeError(
1898
1896
  `You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`
1899
1897
  );
@@ -1953,7 +1951,7 @@ const JestChaiExpect = (chai, utils) => {
1953
1951
  `expect.poll() is not supported in combination with .rejects`
1954
1952
  );
1955
1953
  }
1956
- if (typeof (wrapper == null ? undefined : wrapper.then) !== "function") {
1954
+ if (typeof (wrapper == null ? void 0 : wrapper.then) !== "function") {
1957
1955
  throw new TypeError(
1958
1956
  `You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`
1959
1957
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "3.0.5",
4
+ "version": "3.0.7",
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": "^5.1.2",
33
+ "chai": "^5.2.0",
34
34
  "tinyrainbow": "^2.0.0",
35
- "@vitest/spy": "3.0.5",
36
- "@vitest/utils": "3.0.5"
35
+ "@vitest/spy": "3.0.7",
36
+ "@vitest/utils": "3.0.7"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/chai": "4.3.6",
40
40
  "rollup-plugin-copy": "^3.5.0",
41
- "@vitest/runner": "3.0.5"
41
+ "@vitest/runner": "3.0.7"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rimraf dist && rollup -c",