@vitest/expect 0.32.0 → 0.32.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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { use } from 'chai';
2
2
  import { stringify, Constructable } from '@vitest/utils';
3
3
  export { setupColors } from '@vitest/utils';
4
+ import { diff } from '@vitest/utils/diff';
5
+ export { DiffOptions } from '@vitest/utils/diff';
4
6
 
5
7
  type Formatter = (input: string | number | null | undefined) => string;
6
8
 
@@ -34,11 +36,11 @@ declare function getMatcherUtils(): {
34
36
  printReceived: (object: unknown) => string;
35
37
  printExpected: (value: unknown) => string;
36
38
  };
37
- declare function diff(a: any, b: any, options?: DiffOptions): string;
38
39
 
39
40
  type FirstFunctionArgument<T> = T extends (arg: infer A) => unknown ? A : never;
40
41
  type ChaiPlugin = FirstFunctionArgument<typeof use>;
41
42
  type Tester = (a: any, b: any) => boolean | undefined;
43
+
42
44
  interface MatcherHintOptions {
43
45
  comment?: string;
44
46
  expectedColor?: Formatter;
@@ -49,27 +51,6 @@ interface MatcherHintOptions {
49
51
  secondArgument?: string;
50
52
  secondArgumentColor?: Formatter;
51
53
  }
52
- interface DiffOptions {
53
- aAnnotation?: string;
54
- aColor?: Formatter;
55
- aIndicator?: string;
56
- bAnnotation?: string;
57
- bColor?: Formatter;
58
- bIndicator?: string;
59
- changeColor?: Formatter;
60
- changeLineTrailingSpaceColor?: Formatter;
61
- commonColor?: Formatter;
62
- commonIndicator?: string;
63
- commonLineTrailingSpaceColor?: Formatter;
64
- contextLines?: number;
65
- emptyFirstOrLastLinePlaceholder?: string;
66
- expand?: boolean;
67
- includeChangeCounts?: boolean;
68
- omitAnnotationLines?: boolean;
69
- patchColor?: Formatter;
70
- compareKeys?: any;
71
- showLegend?: boolean;
72
- }
73
54
  interface MatcherState {
74
55
  assertionCalls: number;
75
56
  currentTestName?: string;
@@ -107,6 +88,7 @@ interface RawMatcherFn<T extends MatcherState = MatcherState> {
107
88
  type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
108
89
  interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
109
90
  <T>(actual: T, message?: string): Assertion<T>;
91
+ unreachable(message?: string): never;
110
92
  soft<T>(actual: T, message?: string): Assertion<T>;
111
93
  extend(expects: MatchersObject): void;
112
94
  assertions(expected: number): void;
@@ -272,4 +254,4 @@ declare const JestChaiExpect: ChaiPlugin;
272
254
 
273
255
  declare const JestExtend: ChaiPlugin;
274
256
 
275
- export { Any, Anything, ArrayContaining, Assertion, AsymmetricMatcher, AsymmetricMatcherInterface, AsymmetricMatchersContaining, AsyncExpectationResult, ChaiPlugin, DiffOptions, ExpectStatic, ExpectationResult, FirstFunctionArgument, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, MatcherHintOptions, MatcherState, MatchersObject, ObjectContaining, RawMatcherFn, StringContaining, StringMatching, SyncExpectationResult, Tester, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, setState, sparseArrayEquality, subsetEquality, typeEquality };
257
+ export { Any, Anything, ArrayContaining, Assertion, AsymmetricMatcher, AsymmetricMatcherInterface, AsymmetricMatchersContaining, AsyncExpectationResult, ChaiPlugin, ExpectStatic, ExpectationResult, FirstFunctionArgument, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, MatcherHintOptions, MatcherState, MatchersObject, ObjectContaining, RawMatcherFn, StringContaining, StringMatching, SyncExpectationResult, Tester, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, setState, sparseArrayEquality, subsetEquality, typeEquality };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { getColors, stringify, isObject, assertTypes } from '@vitest/utils';
2
2
  export { setupColors } from '@vitest/utils';
3
- import { unifiedDiff } from '@vitest/utils/diff';
3
+ import { diff } from '@vitest/utils/diff';
4
4
  import { AssertionError, util } from 'chai';
5
5
  import { isMockFunction } from '@vitest/spy';
6
6
  import { processError } from '@vitest/utils/error';
@@ -101,11 +101,6 @@ function getMatcherUtils() {
101
101
  printExpected
102
102
  };
103
103
  }
104
- function diff(a, b, options) {
105
- return unifiedDiff(b, a, {
106
- showLegend: options == null ? void 0 : options.showLegend
107
- });
108
- }
109
104
 
110
105
  function equals(a, b, customTesters, strictCheck) {
111
106
  customTesters = customTesters || [];
@@ -809,7 +804,8 @@ const JestChaiExpect = (chai, utils) => {
809
804
  Boolean(obj),
810
805
  "expected #{this} to be truthy",
811
806
  "expected #{this} to not be truthy",
812
- obj
807
+ obj,
808
+ false
813
809
  );
814
810
  });
815
811
  def("toBeFalsy", function() {
@@ -818,7 +814,8 @@ const JestChaiExpect = (chai, utils) => {
818
814
  !obj,
819
815
  "expected #{this} to be falsy",
820
816
  "expected #{this} to not be falsy",
821
- obj
817
+ obj,
818
+ false
822
819
  );
823
820
  });
824
821
  def("toBeGreaterThan", function(expected) {
@@ -830,7 +827,8 @@ const JestChaiExpect = (chai, utils) => {
830
827
  `expected ${actual} to be greater than ${expected}`,
831
828
  `expected ${actual} to be not greater than ${expected}`,
832
829
  actual,
833
- expected
830
+ expected,
831
+ false
834
832
  );
835
833
  });
836
834
  def("toBeGreaterThanOrEqual", function(expected) {
@@ -842,7 +840,8 @@ const JestChaiExpect = (chai, utils) => {
842
840
  `expected ${actual} to be greater than or equal to ${expected}`,
843
841
  `expected ${actual} to be not greater than or equal to ${expected}`,
844
842
  actual,
845
- expected
843
+ expected,
844
+ false
846
845
  );
847
846
  });
848
847
  def("toBeLessThan", function(expected) {
@@ -854,7 +853,8 @@ const JestChaiExpect = (chai, utils) => {
854
853
  `expected ${actual} to be less than ${expected}`,
855
854
  `expected ${actual} to be not less than ${expected}`,
856
855
  actual,
857
- expected
856
+ expected,
857
+ false
858
858
  );
859
859
  });
860
860
  def("toBeLessThanOrEqual", function(expected) {
@@ -866,7 +866,8 @@ const JestChaiExpect = (chai, utils) => {
866
866
  `expected ${actual} to be less than or equal to ${expected}`,
867
867
  `expected ${actual} to be not less than or equal to ${expected}`,
868
868
  actual,
869
- expected
869
+ expected,
870
+ false
870
871
  );
871
872
  });
872
873
  def("toBeNaN", function() {
@@ -942,7 +943,8 @@ const JestChaiExpect = (chai, utils) => {
942
943
  `expected #{this} to be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
943
944
  `expected #{this} to not be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
944
945
  received,
945
- expected
946
+ expected,
947
+ false
946
948
  );
947
949
  });
948
950
  const assertIsMock = (assertion) => {
@@ -969,12 +971,13 @@ const JestChaiExpect = (chai, utils) => {
969
971
  msg += c().gray(`
970
972
 
971
973
  Received:
974
+
972
975
  ${spy.mock.calls.map((callArg, i) => {
973
- let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
976
+ let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
974
977
 
975
978
  `);
976
979
  if (actualCall)
977
- methodCall += diff(actualCall, callArg, { showLegend: false });
980
+ methodCall += diff(actualCall, callArg, { omitAnnotationLines: true });
978
981
  else
979
982
  methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
980
983
  methodCall += "\n";
@@ -991,12 +994,13 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
991
994
  msg += c().gray(`
992
995
 
993
996
  Received:
997
+
994
998
  ${spy.mock.results.map((callReturn, i) => {
995
- let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
999
+ let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
996
1000
 
997
1001
  `);
998
1002
  if (actualReturn)
999
- methodCall += diff(actualReturn, callReturn.value, { showLegend: false });
1003
+ methodCall += diff(actualReturn, callReturn.value, { omitAnnotationLines: true });
1000
1004
  else
1001
1005
  methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
1002
1006
  methodCall += "\n";
@@ -1017,7 +1021,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1017
1021
  `expected "${spyName}" to be called #{exp} times`,
1018
1022
  `expected "${spyName}" to not be called #{exp} times`,
1019
1023
  number,
1020
- callCount
1024
+ callCount,
1025
+ false
1021
1026
  );
1022
1027
  });
1023
1028
  def("toHaveBeenCalledOnce", function() {
@@ -1029,7 +1034,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1029
1034
  `expected "${spyName}" to be called once`,
1030
1035
  `expected "${spyName}" to not be called once`,
1031
1036
  1,
1032
- callCount
1037
+ callCount,
1038
+ false
1033
1039
  );
1034
1040
  });
1035
1041
  def(["toHaveBeenCalled", "toBeCalled"], function() {
@@ -1133,7 +1139,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1133
1139
  `expected error to be instance of ${name}`,
1134
1140
  `expected error not to be instance of ${name}`,
1135
1141
  expected,
1136
- thrown
1142
+ thrown,
1143
+ false
1137
1144
  );
1138
1145
  }
1139
1146
  if (expected instanceof Error) {
@@ -1152,7 +1159,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1152
1159
  "expected error to match asymmetric matcher",
1153
1160
  "expected error not to match asymmetric matcher",
1154
1161
  matcher.toString(),
1155
- thrown
1162
+ thrown,
1163
+ false
1156
1164
  );
1157
1165
  }
1158
1166
  throw new Error(`"toThrow" expects string, RegExp, function, Error instance or asymmetric matcher, got "${typeof expected}"`);
@@ -1166,7 +1174,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1166
1174
  `expected "${spyName}" to be successfully called at least once`,
1167
1175
  `expected "${spyName}" to not be successfully called`,
1168
1176
  calledAndNotThrew,
1169
- !calledAndNotThrew
1177
+ !calledAndNotThrew,
1178
+ false
1170
1179
  );
1171
1180
  });
1172
1181
  def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
@@ -1178,7 +1187,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
1178
1187
  `expected "${spyName}" to be successfully called ${times} times`,
1179
1188
  `expected "${spyName}" to not be successfully called ${times} times`,
1180
1189
  `expected number of returns: ${times}`,
1181
- `received number of returns: ${successfulReturns}`
1190
+ `received number of returns: ${successfulReturns}`,
1191
+ false
1182
1192
  );
1183
1193
  });
1184
1194
  def(["toHaveReturnedWith", "toReturnWith"], function(value) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/expect",
3
3
  "type": "module",
4
- "version": "0.32.0",
4
+ "version": "0.32.1",
5
5
  "description": "Jest's expect matchers as a Chai plugin",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -30,12 +30,12 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "chai": "^4.3.7",
33
- "@vitest/utils": "0.32.0",
34
- "@vitest/spy": "0.32.0"
33
+ "@vitest/spy": "0.32.1",
34
+ "@vitest/utils": "0.32.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "picocolors": "^1.0.0",
38
- "@vitest/runner": "0.32.0"
38
+ "@vitest/runner": "0.32.1"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "rimraf dist && rollup -c",