@noma.to/qwik-testing-library 1.0.4 → 1.1.0

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 (100) hide show
  1. package/README.md +61 -0
  2. package/lib/_virtual/_commonjsHelpers.qwik.cjs +2 -0
  3. package/lib/_virtual/_commonjsHelpers.qwik.mjs +2 -0
  4. package/lib/_virtual/sourcemap-codec.umd.qwik.cjs +4 -0
  5. package/lib/_virtual/sourcemap-codec.umd.qwik.mjs +4 -0
  6. package/lib/index.qwik.cjs +4 -0
  7. package/lib/index.qwik.mjs +4 -0
  8. package/lib/lib/mock.qwik.cjs +14 -0
  9. package/lib/lib/mock.qwik.mjs +14 -0
  10. package/lib/lib/qwik-testing-library.qwik.cjs +4 -0
  11. package/lib/lib/qwik-testing-library.qwik.mjs +4 -0
  12. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.qwik.cjs +425 -0
  13. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.qwik.mjs +425 -0
  14. package/lib/node_modules/.pnpm/@vitest_expect@2.1.1/node_modules/@vitest/expect/dist/index.qwik.cjs +1967 -0
  15. package/lib/node_modules/.pnpm/@vitest_expect@2.1.1/node_modules/@vitest/expect/dist/index.qwik.mjs +1967 -0
  16. package/lib/node_modules/.pnpm/@vitest_pretty-format@2.1.1/node_modules/@vitest/pretty-format/dist/index.qwik.cjs +1202 -0
  17. package/lib/node_modules/.pnpm/@vitest_pretty-format@2.1.1/node_modules/@vitest/pretty-format/dist/index.qwik.mjs +1202 -0
  18. package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/chunk-tasks.qwik.cjs +44 -0
  19. package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs +44 -0
  20. package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/index.qwik.cjs +665 -0
  21. package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/index.qwik.mjs +665 -0
  22. package/lib/node_modules/.pnpm/@vitest_snapshot@2.1.1/node_modules/@vitest/snapshot/dist/index.qwik.cjs +1641 -0
  23. package/lib/node_modules/.pnpm/@vitest_snapshot@2.1.1/node_modules/@vitest/snapshot/dist/index.qwik.mjs +1641 -0
  24. package/lib/node_modules/.pnpm/@vitest_spy@2.1.1/node_modules/@vitest/spy/dist/index.qwik.cjs +148 -0
  25. package/lib/node_modules/.pnpm/@vitest_spy@2.1.1/node_modules/@vitest/spy/dist/index.qwik.mjs +148 -0
  26. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/chunk-display.qwik.cjs +158 -0
  27. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/chunk-display.qwik.mjs +158 -0
  28. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/diff.qwik.cjs +1731 -0
  29. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/diff.qwik.mjs +1731 -0
  30. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/error.qwik.cjs +137 -0
  31. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/error.qwik.mjs +137 -0
  32. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/helpers.qwik.cjs +150 -0
  33. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/helpers.qwik.mjs +150 -0
  34. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/index.qwik.cjs +81 -0
  35. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/index.qwik.mjs +81 -0
  36. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/source-map.qwik.cjs +216 -0
  37. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/source-map.qwik.mjs +216 -0
  38. package/lib/node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.qwik.cjs +3905 -0
  39. package/lib/node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.qwik.mjs +3905 -0
  40. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/arguments.qwik.cjs +9 -0
  41. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/arguments.qwik.mjs +10 -0
  42. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/array.qwik.cjs +16 -0
  43. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/array.qwik.mjs +17 -0
  44. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/bigint.qwik.cjs +9 -0
  45. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/bigint.qwik.mjs +10 -0
  46. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/class.qwik.cjs +16 -0
  47. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/class.qwik.mjs +17 -0
  48. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/date.qwik.cjs +12 -0
  49. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/date.qwik.mjs +13 -0
  50. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/error.qwik.cjs +30 -0
  51. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/error.qwik.mjs +31 -0
  52. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/function.qwik.cjs +11 -0
  53. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/function.qwik.mjs +12 -0
  54. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/helpers.qwik.cjs +160 -0
  55. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/helpers.qwik.mjs +160 -0
  56. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/html.qwik.cjs +36 -0
  57. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/html.qwik.mjs +36 -0
  58. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/index.qwik.cjs +130 -0
  59. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/index.qwik.mjs +130 -0
  60. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/map.qwik.cjs +25 -0
  61. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/map.qwik.mjs +26 -0
  62. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/number.qwik.cjs +19 -0
  63. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/number.qwik.mjs +20 -0
  64. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/object.qwik.cjs +24 -0
  65. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/object.qwik.mjs +25 -0
  66. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/promise.qwik.cjs +17 -0
  67. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/promise.qwik.mjs +18 -0
  68. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/regexp.qwik.cjs +9 -0
  69. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/regexp.qwik.mjs +10 -0
  70. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/set.qwik.cjs +16 -0
  71. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/set.qwik.mjs +17 -0
  72. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/string.qwik.cjs +24 -0
  73. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/string.qwik.mjs +25 -0
  74. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/symbol.qwik.cjs +8 -0
  75. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/symbol.qwik.mjs +9 -0
  76. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/typedarray.qwik.cjs +34 -0
  77. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/typedarray.qwik.mjs +35 -0
  78. package/lib/node_modules/.pnpm/magic-string@0.30.11/node_modules/magic-string/dist/magic-string.es.qwik.cjs +968 -0
  79. package/lib/node_modules/.pnpm/magic-string@0.30.11/node_modules/magic-string/dist/magic-string.es.qwik.mjs +968 -0
  80. package/lib/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.qwik.cjs +101 -0
  81. package/lib/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.qwik.mjs +101 -0
  82. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.cjs +7 -0
  83. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.mjs +8 -0
  84. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.cjs +80 -0
  85. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.mjs +80 -0
  86. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.cjs +104 -0
  87. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.mjs +104 -0
  88. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.cjs +8 -0
  89. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.mjs +8 -0
  90. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/base.BlXpj3e_.qwik.cjs +6 -0
  91. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/base.BlXpj3e_.qwik.mjs +6 -0
  92. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.cjs +56 -0
  93. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.mjs +56 -0
  94. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/utils.Ck2hJTRs.qwik.cjs +16 -0
  95. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/utils.Ck2hJTRs.qwik.mjs +16 -0
  96. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/vi.D6IHiKAI.qwik.cjs +2556 -0
  97. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/vi.D6IHiKAI.qwik.mjs +2556 -0
  98. package/lib-types/lib/mock.d.ts +34 -0
  99. package/lib-types/lib/qwik-testing-library.d.ts +2 -1
  100. package/package.json +5 -4
@@ -0,0 +1,1967 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ const browser = require("../../../../../tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.cjs");
7
+ const diff = require("../../../../../@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/diff.qwik.cjs");
8
+ const index = require("../../../../../@vitest_spy@2.1.1/node_modules/@vitest/spy/dist/index.qwik.cjs");
9
+ const error = require("../../../../../@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/error.qwik.cjs");
10
+ const chai = require("../../../../../chai@5.1.1/node_modules/chai/chai.qwik.cjs");
11
+ const helpers = require("../../../../../@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/helpers.qwik.cjs");
12
+ const chunkDisplay = require("../../../../../@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/chunk-display.qwik.cjs");
13
+ const MATCHERS_OBJECT = Symbol.for("matchers-object");
14
+ const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
15
+ const GLOBAL_EXPECT = Symbol.for("expect-global");
16
+ const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for(
17
+ "asymmetric-matchers-object"
18
+ );
19
+ if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
20
+ const globalState = /* @__PURE__ */ new WeakMap();
21
+ const matchers = /* @__PURE__ */ Object.create(null);
22
+ const customEqualityTesters = [];
23
+ const assymetricMatchers = /* @__PURE__ */ Object.create(null);
24
+ Object.defineProperty(globalThis, MATCHERS_OBJECT, {
25
+ get: () => globalState
26
+ });
27
+ Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
28
+ configurable: true,
29
+ get: () => ({
30
+ state: globalState.get(globalThis[GLOBAL_EXPECT]),
31
+ matchers,
32
+ customEqualityTesters
33
+ })
34
+ });
35
+ Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
36
+ get: () => assymetricMatchers
37
+ });
38
+ }
39
+ function getState(expect) {
40
+ return globalThis[MATCHERS_OBJECT].get(expect);
41
+ }
42
+ function setState(state, expect) {
43
+ const map = globalThis[MATCHERS_OBJECT];
44
+ const current = map.get(expect) || {};
45
+ const results = Object.defineProperties(current, {
46
+ ...Object.getOwnPropertyDescriptors(current),
47
+ ...Object.getOwnPropertyDescriptors(state)
48
+ });
49
+ map.set(expect, results);
50
+ }
51
+ const EXPECTED_COLOR = browser.default.green;
52
+ const RECEIVED_COLOR = browser.default.red;
53
+ const INVERTED_COLOR = browser.default.inverse;
54
+ const BOLD_WEIGHT = browser.default.bold;
55
+ const DIM_COLOR = browser.default.dim;
56
+ function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
57
+ const {
58
+ comment = "",
59
+ isDirectExpectCall = false,
60
+ // seems redundant with received === ''
61
+ isNot = false,
62
+ promise = "",
63
+ secondArgument = "",
64
+ expectedColor = EXPECTED_COLOR,
65
+ receivedColor = RECEIVED_COLOR,
66
+ secondArgumentColor = EXPECTED_COLOR
67
+ } = options;
68
+ let hint = "";
69
+ let dimString = "expect";
70
+ if (!isDirectExpectCall && received !== "") {
71
+ hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
72
+ dimString = ")";
73
+ }
74
+ if (promise !== "") {
75
+ hint += DIM_COLOR(`${dimString}.`) + promise;
76
+ dimString = "";
77
+ }
78
+ if (isNot) {
79
+ hint += `${DIM_COLOR(`${dimString}.`)}not`;
80
+ dimString = "";
81
+ }
82
+ if (matcherName.includes(".")) {
83
+ dimString += matcherName;
84
+ } else {
85
+ hint += DIM_COLOR(`${dimString}.`) + matcherName;
86
+ dimString = "";
87
+ }
88
+ if (expected === "") {
89
+ dimString += "()";
90
+ } else {
91
+ hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
92
+ if (secondArgument) {
93
+ hint += DIM_COLOR(", ") + secondArgumentColor(secondArgument);
94
+ }
95
+ dimString = ")";
96
+ }
97
+ if (comment !== "") {
98
+ dimString += ` // ${comment}`;
99
+ }
100
+ if (dimString !== "") {
101
+ hint += DIM_COLOR(dimString);
102
+ }
103
+ return hint;
104
+ }
105
+ const SPACE_SYMBOL = "·";
106
+ function replaceTrailingSpaces(text) {
107
+ return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
108
+ }
109
+ function printReceived(object) {
110
+ return RECEIVED_COLOR(replaceTrailingSpaces(chunkDisplay.s(object)));
111
+ }
112
+ function printExpected(value) {
113
+ return EXPECTED_COLOR(replaceTrailingSpaces(chunkDisplay.s(value)));
114
+ }
115
+ function getMatcherUtils() {
116
+ return {
117
+ EXPECTED_COLOR,
118
+ RECEIVED_COLOR,
119
+ INVERTED_COLOR,
120
+ BOLD_WEIGHT,
121
+ DIM_COLOR,
122
+ diff: diff.diff,
123
+ matcherHint,
124
+ printReceived,
125
+ printExpected,
126
+ printDiffOrStringify: diff.printDiffOrStringify
127
+ };
128
+ }
129
+ function addCustomEqualityTesters(newTesters) {
130
+ if (!Array.isArray(newTesters)) {
131
+ throw new TypeError(
132
+ `expect.customEqualityTesters: Must be set to an array of Testers. Was given "${helpers.getType(
133
+ newTesters
134
+ )}"`
135
+ );
136
+ }
137
+ globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters.push(
138
+ ...newTesters
139
+ );
140
+ }
141
+ function getCustomEqualityTesters() {
142
+ return globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters;
143
+ }
144
+ function equals(a, b, customTesters, strictCheck) {
145
+ customTesters = customTesters || [];
146
+ return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
147
+ }
148
+ function isAsymmetric(obj) {
149
+ return !!obj && typeof obj === "object" && "asymmetricMatch" in obj && isA("Function", obj.asymmetricMatch);
150
+ }
151
+ function asymmetricMatch(a, b) {
152
+ const asymmetricA = isAsymmetric(a);
153
+ const asymmetricB = isAsymmetric(b);
154
+ if (asymmetricA && asymmetricB) {
155
+ return void 0;
156
+ }
157
+ if (asymmetricA) {
158
+ return a.asymmetricMatch(b);
159
+ }
160
+ if (asymmetricB) {
161
+ return b.asymmetricMatch(a);
162
+ }
163
+ }
164
+ function eq(a, b, aStack, bStack, customTesters, hasKey2) {
165
+ let result = true;
166
+ const asymmetricResult = asymmetricMatch(a, b);
167
+ if (asymmetricResult !== void 0) {
168
+ return asymmetricResult;
169
+ }
170
+ const testerContext = { equals };
171
+ for (let i = 0; i < customTesters.length; i++) {
172
+ const customTesterResult = customTesters[i].call(
173
+ testerContext,
174
+ a,
175
+ b,
176
+ customTesters
177
+ );
178
+ if (customTesterResult !== void 0) {
179
+ return customTesterResult;
180
+ }
181
+ }
182
+ if (a instanceof Error && b instanceof Error) {
183
+ return a.message === b.message;
184
+ }
185
+ if (typeof URL === "function" && a instanceof URL && b instanceof URL) {
186
+ return a.href === b.href;
187
+ }
188
+ if (Object.is(a, b)) {
189
+ return true;
190
+ }
191
+ if (a === null || b === null) {
192
+ return a === b;
193
+ }
194
+ const className = Object.prototype.toString.call(a);
195
+ if (className !== Object.prototype.toString.call(b)) {
196
+ return false;
197
+ }
198
+ switch (className) {
199
+ case "[object Boolean]":
200
+ case "[object String]":
201
+ case "[object Number]":
202
+ if (typeof a !== typeof b) {
203
+ return false;
204
+ } else if (typeof a !== "object" && typeof b !== "object") {
205
+ return Object.is(a, b);
206
+ } else {
207
+ return Object.is(a.valueOf(), b.valueOf());
208
+ }
209
+ case "[object Date]": {
210
+ const numA = +a;
211
+ const numB = +b;
212
+ return numA === numB || Number.isNaN(numA) && Number.isNaN(numB);
213
+ }
214
+ case "[object RegExp]":
215
+ return a.source === b.source && a.flags === b.flags;
216
+ }
217
+ if (typeof a !== "object" || typeof b !== "object") {
218
+ return false;
219
+ }
220
+ if (isDomNode(a) && isDomNode(b)) {
221
+ return a.isEqualNode(b);
222
+ }
223
+ let length = aStack.length;
224
+ while (length--) {
225
+ if (aStack[length] === a) {
226
+ return bStack[length] === b;
227
+ } else if (bStack[length] === b) {
228
+ return false;
229
+ }
230
+ }
231
+ aStack.push(a);
232
+ bStack.push(b);
233
+ if (className === "[object Array]" && a.length !== b.length) {
234
+ return false;
235
+ }
236
+ const aKeys = keys(a, hasKey2);
237
+ let key;
238
+ let size = aKeys.length;
239
+ if (keys(b, hasKey2).length !== size) {
240
+ return false;
241
+ }
242
+ while (size--) {
243
+ key = aKeys[size];
244
+ result = hasKey2(b, key) && eq(a[key], b[key], aStack, bStack, customTesters, hasKey2);
245
+ if (!result) {
246
+ return false;
247
+ }
248
+ }
249
+ aStack.pop();
250
+ bStack.pop();
251
+ return result;
252
+ }
253
+ function keys(obj, hasKey2) {
254
+ const keys2 = [];
255
+ for (const key in obj) {
256
+ if (hasKey2(obj, key)) {
257
+ keys2.push(key);
258
+ }
259
+ }
260
+ return keys2.concat(
261
+ Object.getOwnPropertySymbols(obj).filter(
262
+ (symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable
263
+ )
264
+ );
265
+ }
266
+ function hasDefinedKey(obj, key) {
267
+ return hasKey(obj, key) && obj[key] !== void 0;
268
+ }
269
+ function hasKey(obj, key) {
270
+ return Object.prototype.hasOwnProperty.call(obj, key);
271
+ }
272
+ function isA(typeName, value) {
273
+ return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
274
+ }
275
+ function isDomNode(obj) {
276
+ return obj !== null && typeof obj === "object" && "nodeType" in obj && typeof obj.nodeType === "number" && "nodeName" in obj && typeof obj.nodeName === "string" && "isEqualNode" in obj && typeof obj.isEqualNode === "function";
277
+ }
278
+ const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
279
+ const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
280
+ const IS_LIST_SENTINEL = "@@__IMMUTABLE_LIST__@@";
281
+ const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
282
+ const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
283
+ function isImmutableUnorderedKeyed(maybeKeyed) {
284
+ return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL] && !maybeKeyed[IS_ORDERED_SENTINEL]);
285
+ }
286
+ function isImmutableUnorderedSet(maybeSet) {
287
+ return !!(maybeSet && maybeSet[IS_SET_SENTINEL] && !maybeSet[IS_ORDERED_SENTINEL]);
288
+ }
289
+ function isObjectLiteral(source) {
290
+ return source != null && typeof source === "object" && !Array.isArray(source);
291
+ }
292
+ function isImmutableList(source) {
293
+ return Boolean(source && isObjectLiteral(source) && source[IS_LIST_SENTINEL]);
294
+ }
295
+ function isImmutableOrderedKeyed(source) {
296
+ return Boolean(
297
+ source && isObjectLiteral(source) && source[IS_KEYED_SENTINEL] && source[IS_ORDERED_SENTINEL]
298
+ );
299
+ }
300
+ function isImmutableOrderedSet(source) {
301
+ return Boolean(
302
+ source && isObjectLiteral(source) && source[IS_SET_SENTINEL] && source[IS_ORDERED_SENTINEL]
303
+ );
304
+ }
305
+ function isImmutableRecord(source) {
306
+ return Boolean(source && isObjectLiteral(source) && source[IS_RECORD_SYMBOL]);
307
+ }
308
+ const IteratorSymbol = Symbol.iterator;
309
+ function hasIterator(object) {
310
+ return !!(object != null && object[IteratorSymbol]);
311
+ }
312
+ function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
313
+ if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b)) {
314
+ return void 0;
315
+ }
316
+ if (a.constructor !== b.constructor) {
317
+ return false;
318
+ }
319
+ let length = aStack.length;
320
+ while (length--) {
321
+ if (aStack[length] === a) {
322
+ return bStack[length] === b;
323
+ }
324
+ }
325
+ aStack.push(a);
326
+ bStack.push(b);
327
+ const filteredCustomTesters = [
328
+ ...customTesters.filter((t) => t !== iterableEquality),
329
+ iterableEqualityWithStack
330
+ ];
331
+ function iterableEqualityWithStack(a2, b2) {
332
+ return iterableEquality(a2, b2, [...customTesters], [...aStack], [...bStack]);
333
+ }
334
+ if (a.size !== void 0) {
335
+ if (a.size !== b.size) {
336
+ return false;
337
+ } else if (isA("Set", a) || isImmutableUnorderedSet(a)) {
338
+ let allFound = true;
339
+ for (const aValue of a) {
340
+ if (!b.has(aValue)) {
341
+ let has = false;
342
+ for (const bValue of b) {
343
+ const isEqual = equals(aValue, bValue, filteredCustomTesters);
344
+ if (isEqual === true) {
345
+ has = true;
346
+ }
347
+ }
348
+ if (has === false) {
349
+ allFound = false;
350
+ break;
351
+ }
352
+ }
353
+ }
354
+ aStack.pop();
355
+ bStack.pop();
356
+ return allFound;
357
+ } else if (isA("Map", a) || isImmutableUnorderedKeyed(a)) {
358
+ let allFound = true;
359
+ for (const aEntry of a) {
360
+ if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]), filteredCustomTesters)) {
361
+ let has = false;
362
+ for (const bEntry of b) {
363
+ const matchedKey = equals(
364
+ aEntry[0],
365
+ bEntry[0],
366
+ filteredCustomTesters
367
+ );
368
+ let matchedValue = false;
369
+ if (matchedKey === true) {
370
+ matchedValue = equals(
371
+ aEntry[1],
372
+ bEntry[1],
373
+ filteredCustomTesters
374
+ );
375
+ }
376
+ if (matchedValue === true) {
377
+ has = true;
378
+ }
379
+ }
380
+ if (has === false) {
381
+ allFound = false;
382
+ break;
383
+ }
384
+ }
385
+ }
386
+ aStack.pop();
387
+ bStack.pop();
388
+ return allFound;
389
+ }
390
+ }
391
+ const bIterator = b[IteratorSymbol]();
392
+ for (const aValue of a) {
393
+ const nextB = bIterator.next();
394
+ if (nextB.done || !equals(aValue, nextB.value, filteredCustomTesters)) {
395
+ return false;
396
+ }
397
+ }
398
+ if (!bIterator.next().done) {
399
+ return false;
400
+ }
401
+ if (!isImmutableList(a) && !isImmutableOrderedKeyed(a) && !isImmutableOrderedSet(a) && !isImmutableRecord(a)) {
402
+ const aEntries = Object.entries(a);
403
+ const bEntries = Object.entries(b);
404
+ if (!equals(aEntries, bEntries)) {
405
+ return false;
406
+ }
407
+ }
408
+ aStack.pop();
409
+ bStack.pop();
410
+ return true;
411
+ }
412
+ function hasPropertyInObject(object, key) {
413
+ const shouldTerminate = !object || typeof object !== "object" || object === Object.prototype;
414
+ if (shouldTerminate) {
415
+ return false;
416
+ }
417
+ return Object.prototype.hasOwnProperty.call(object, key) || hasPropertyInObject(Object.getPrototypeOf(object), key);
418
+ }
419
+ function isObjectWithKeys(a) {
420
+ return helpers.isObject(a) && !(a instanceof Error) && !Array.isArray(a) && !(a instanceof Date);
421
+ }
422
+ function subsetEquality(object, subset, customTesters = []) {
423
+ const filteredCustomTesters = customTesters.filter(
424
+ (t) => t !== subsetEquality
425
+ );
426
+ const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
427
+ if (!isObjectWithKeys(subset2)) {
428
+ return void 0;
429
+ }
430
+ return Object.keys(subset2).every((key) => {
431
+ if (subset2[key] != null && typeof subset2[key] === "object") {
432
+ if (seenReferences.has(subset2[key])) {
433
+ return equals(object2[key], subset2[key], filteredCustomTesters);
434
+ }
435
+ seenReferences.set(subset2[key], true);
436
+ }
437
+ const result = object2 != null && hasPropertyInObject(object2, key) && equals(object2[key], subset2[key], [
438
+ ...filteredCustomTesters,
439
+ subsetEqualityWithContext(seenReferences)
440
+ ]);
441
+ seenReferences.delete(subset2[key]);
442
+ return result;
443
+ });
444
+ };
445
+ return subsetEqualityWithContext()(object, subset);
446
+ }
447
+ function typeEquality(a, b) {
448
+ if (a == null || b == null || a.constructor === b.constructor) {
449
+ return void 0;
450
+ }
451
+ return false;
452
+ }
453
+ function arrayBufferEquality(a, b) {
454
+ let dataViewA = a;
455
+ let dataViewB = b;
456
+ if (!(a instanceof DataView && b instanceof DataView)) {
457
+ if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer)) {
458
+ return void 0;
459
+ }
460
+ try {
461
+ dataViewA = new DataView(a);
462
+ dataViewB = new DataView(b);
463
+ } catch {
464
+ return void 0;
465
+ }
466
+ }
467
+ if (dataViewA.byteLength !== dataViewB.byteLength) {
468
+ return false;
469
+ }
470
+ for (let i = 0; i < dataViewA.byteLength; i++) {
471
+ if (dataViewA.getUint8(i) !== dataViewB.getUint8(i)) {
472
+ return false;
473
+ }
474
+ }
475
+ return true;
476
+ }
477
+ function sparseArrayEquality(a, b, customTesters = []) {
478
+ if (!Array.isArray(a) || !Array.isArray(b)) {
479
+ return void 0;
480
+ }
481
+ const aKeys = Object.keys(a);
482
+ const bKeys = Object.keys(b);
483
+ const filteredCustomTesters = customTesters.filter(
484
+ (t) => t !== sparseArrayEquality
485
+ );
486
+ return equals(a, b, filteredCustomTesters, true) && equals(aKeys, bKeys);
487
+ }
488
+ function generateToBeMessage(deepEqualityName, expected = "#{this}", actual = "#{exp}") {
489
+ const toBeMessage = `expected ${expected} to be ${actual} // Object.is equality`;
490
+ if (["toStrictEqual", "toEqual"].includes(deepEqualityName)) {
491
+ return `${toBeMessage}
492
+
493
+ If it should pass with deep equality, replace "toBe" with "${deepEqualityName}"
494
+
495
+ Expected: ${expected}
496
+ Received: serializes to the same string
497
+ `;
498
+ }
499
+ return toBeMessage;
500
+ }
501
+ function pluralize(word, count) {
502
+ return `${count} ${word}${count === 1 ? "" : "s"}`;
503
+ }
504
+ function getObjectKeys(object) {
505
+ return [
506
+ ...Object.keys(object),
507
+ ...Object.getOwnPropertySymbols(object).filter(
508
+ (s) => {
509
+ var _a;
510
+ return (_a = Object.getOwnPropertyDescriptor(object, s)) == null ? void 0 : _a.enumerable;
511
+ }
512
+ )
513
+ ];
514
+ }
515
+ function getObjectSubset(object, subset, customTesters = []) {
516
+ let stripped = 0;
517
+ const getObjectSubsetWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
518
+ if (Array.isArray(object2)) {
519
+ if (Array.isArray(subset2) && subset2.length === object2.length) {
520
+ return subset2.map(
521
+ (sub, i) => getObjectSubsetWithContext(seenReferences)(object2[i], sub)
522
+ );
523
+ }
524
+ } else if (object2 instanceof Date) {
525
+ return object2;
526
+ } else if (helpers.isObject(object2) && helpers.isObject(subset2)) {
527
+ if (equals(object2, subset2, [
528
+ ...customTesters,
529
+ iterableEquality,
530
+ subsetEquality
531
+ ])) {
532
+ return subset2;
533
+ }
534
+ const trimmed = {};
535
+ seenReferences.set(object2, trimmed);
536
+ for (const key of getObjectKeys(object2)) {
537
+ if (hasPropertyInObject(subset2, key)) {
538
+ trimmed[key] = seenReferences.has(object2[key]) ? seenReferences.get(object2[key]) : getObjectSubsetWithContext(seenReferences)(
539
+ object2[key],
540
+ subset2[key]
541
+ );
542
+ } else {
543
+ if (!seenReferences.has(object2[key])) {
544
+ stripped += 1;
545
+ if (helpers.isObject(object2[key])) {
546
+ stripped += getObjectKeys(object2[key]).length;
547
+ }
548
+ getObjectSubsetWithContext(seenReferences)(
549
+ object2[key],
550
+ subset2[key]
551
+ );
552
+ }
553
+ }
554
+ }
555
+ if (getObjectKeys(trimmed).length > 0) {
556
+ return trimmed;
557
+ }
558
+ }
559
+ return object2;
560
+ };
561
+ return { subset: getObjectSubsetWithContext()(object, subset), stripped };
562
+ }
563
+ class AsymmetricMatcher {
564
+ constructor(sample, inverse = false) {
565
+ // should have "jest" to be compatible with its ecosystem
566
+ __publicField(this, "$$typeof", Symbol.for("jest.asymmetricMatcher"));
567
+ this.sample = sample;
568
+ this.inverse = inverse;
569
+ }
570
+ getMatcherContext(expect) {
571
+ return {
572
+ ...getState(expect || globalThis[GLOBAL_EXPECT]),
573
+ equals,
574
+ isNot: this.inverse,
575
+ customTesters: getCustomEqualityTesters(),
576
+ utils: {
577
+ ...getMatcherUtils(),
578
+ diff: diff.diff,
579
+ stringify: chunkDisplay.s,
580
+ iterableEquality,
581
+ subsetEquality
582
+ }
583
+ };
584
+ }
585
+ // implement custom chai/loupe inspect for better AssertionError.message formatting
586
+ // https://github.com/chaijs/loupe/blob/9b8a6deabcd50adc056a64fb705896194710c5c6/src/index.ts#L29
587
+ [Symbol.for("chai/inspect")](options) {
588
+ const result = chunkDisplay.s(this, options.depth, { min: true });
589
+ if (result.length <= options.truncate) {
590
+ return result;
591
+ }
592
+ return `${this.toString()}{…}`;
593
+ }
594
+ }
595
+ class StringContaining extends AsymmetricMatcher {
596
+ constructor(sample, inverse = false) {
597
+ if (!isA("String", sample)) {
598
+ throw new Error("Expected is not a string");
599
+ }
600
+ super(sample, inverse);
601
+ }
602
+ asymmetricMatch(other) {
603
+ const result = isA("String", other) && other.includes(this.sample);
604
+ return this.inverse ? !result : result;
605
+ }
606
+ toString() {
607
+ return `String${this.inverse ? "Not" : ""}Containing`;
608
+ }
609
+ getExpectedType() {
610
+ return "string";
611
+ }
612
+ }
613
+ class Anything extends AsymmetricMatcher {
614
+ asymmetricMatch(other) {
615
+ return other != null;
616
+ }
617
+ toString() {
618
+ return "Anything";
619
+ }
620
+ toAsymmetricMatcher() {
621
+ return "Anything";
622
+ }
623
+ }
624
+ class ObjectContaining extends AsymmetricMatcher {
625
+ constructor(sample, inverse = false) {
626
+ super(sample, inverse);
627
+ }
628
+ getPrototype(obj) {
629
+ if (Object.getPrototypeOf) {
630
+ return Object.getPrototypeOf(obj);
631
+ }
632
+ if (obj.constructor.prototype === obj) {
633
+ return null;
634
+ }
635
+ return obj.constructor.prototype;
636
+ }
637
+ hasProperty(obj, property) {
638
+ if (!obj) {
639
+ return false;
640
+ }
641
+ if (Object.prototype.hasOwnProperty.call(obj, property)) {
642
+ return true;
643
+ }
644
+ return this.hasProperty(this.getPrototype(obj), property);
645
+ }
646
+ asymmetricMatch(other) {
647
+ if (typeof this.sample !== "object") {
648
+ throw new TypeError(
649
+ `You must provide an object to ${this.toString()}, not '${typeof this.sample}'.`
650
+ );
651
+ }
652
+ let result = true;
653
+ const matcherContext = this.getMatcherContext();
654
+ for (const property in this.sample) {
655
+ if (!this.hasProperty(other, property) || !equals(
656
+ this.sample[property],
657
+ other[property],
658
+ matcherContext.customTesters
659
+ )) {
660
+ result = false;
661
+ break;
662
+ }
663
+ }
664
+ return this.inverse ? !result : result;
665
+ }
666
+ toString() {
667
+ return `Object${this.inverse ? "Not" : ""}Containing`;
668
+ }
669
+ getExpectedType() {
670
+ return "object";
671
+ }
672
+ }
673
+ class ArrayContaining extends AsymmetricMatcher {
674
+ constructor(sample, inverse = false) {
675
+ super(sample, inverse);
676
+ }
677
+ asymmetricMatch(other) {
678
+ if (!Array.isArray(this.sample)) {
679
+ throw new TypeError(
680
+ `You must provide an array to ${this.toString()}, not '${typeof this.sample}'.`
681
+ );
682
+ }
683
+ const matcherContext = this.getMatcherContext();
684
+ const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every(
685
+ (item) => other.some(
686
+ (another) => equals(item, another, matcherContext.customTesters)
687
+ )
688
+ );
689
+ return this.inverse ? !result : result;
690
+ }
691
+ toString() {
692
+ return `Array${this.inverse ? "Not" : ""}Containing`;
693
+ }
694
+ getExpectedType() {
695
+ return "array";
696
+ }
697
+ }
698
+ class Any extends AsymmetricMatcher {
699
+ constructor(sample) {
700
+ if (typeof sample === "undefined") {
701
+ throw new TypeError(
702
+ "any() expects to be passed a constructor function. Please pass one or use anything() to match any object."
703
+ );
704
+ }
705
+ super(sample);
706
+ }
707
+ fnNameFor(func) {
708
+ if (func.name) {
709
+ return func.name;
710
+ }
711
+ const functionToString = Function.prototype.toString;
712
+ const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*(?:\*\s*)?([\w$]+)\s*\(/);
713
+ return matches ? matches[1] : "<anonymous>";
714
+ }
715
+ asymmetricMatch(other) {
716
+ if (this.sample === String) {
717
+ return typeof other == "string" || other instanceof String;
718
+ }
719
+ if (this.sample === Number) {
720
+ return typeof other == "number" || other instanceof Number;
721
+ }
722
+ if (this.sample === Function) {
723
+ return typeof other == "function" || other instanceof Function;
724
+ }
725
+ if (this.sample === Boolean) {
726
+ return typeof other == "boolean" || other instanceof Boolean;
727
+ }
728
+ if (this.sample === BigInt) {
729
+ return typeof other == "bigint" || other instanceof BigInt;
730
+ }
731
+ if (this.sample === Symbol) {
732
+ return typeof other == "symbol" || other instanceof Symbol;
733
+ }
734
+ if (this.sample === Object) {
735
+ return typeof other == "object";
736
+ }
737
+ return other instanceof this.sample;
738
+ }
739
+ toString() {
740
+ return "Any";
741
+ }
742
+ getExpectedType() {
743
+ if (this.sample === String) {
744
+ return "string";
745
+ }
746
+ if (this.sample === Number) {
747
+ return "number";
748
+ }
749
+ if (this.sample === Function) {
750
+ return "function";
751
+ }
752
+ if (this.sample === Object) {
753
+ return "object";
754
+ }
755
+ if (this.sample === Boolean) {
756
+ return "boolean";
757
+ }
758
+ return this.fnNameFor(this.sample);
759
+ }
760
+ toAsymmetricMatcher() {
761
+ return `Any<${this.fnNameFor(this.sample)}>`;
762
+ }
763
+ }
764
+ class StringMatching extends AsymmetricMatcher {
765
+ constructor(sample, inverse = false) {
766
+ if (!isA("String", sample) && !isA("RegExp", sample)) {
767
+ throw new Error("Expected is not a String or a RegExp");
768
+ }
769
+ super(new RegExp(sample), inverse);
770
+ }
771
+ asymmetricMatch(other) {
772
+ const result = isA("String", other) && this.sample.test(other);
773
+ return this.inverse ? !result : result;
774
+ }
775
+ toString() {
776
+ return `String${this.inverse ? "Not" : ""}Matching`;
777
+ }
778
+ getExpectedType() {
779
+ return "string";
780
+ }
781
+ }
782
+ class CloseTo extends AsymmetricMatcher {
783
+ constructor(sample, precision = 2, inverse = false) {
784
+ if (!isA("Number", sample)) {
785
+ throw new Error("Expected is not a Number");
786
+ }
787
+ if (!isA("Number", precision)) {
788
+ throw new Error("Precision is not a Number");
789
+ }
790
+ super(sample);
791
+ __publicField(this, "precision");
792
+ this.inverse = inverse;
793
+ this.precision = precision;
794
+ }
795
+ asymmetricMatch(other) {
796
+ if (!isA("Number", other)) {
797
+ return false;
798
+ }
799
+ let result = false;
800
+ if (other === Number.POSITIVE_INFINITY && this.sample === Number.POSITIVE_INFINITY) {
801
+ result = true;
802
+ } else if (other === Number.NEGATIVE_INFINITY && this.sample === Number.NEGATIVE_INFINITY) {
803
+ result = true;
804
+ } else {
805
+ result = Math.abs(this.sample - other) < 10 ** -this.precision / 2;
806
+ }
807
+ return this.inverse ? !result : result;
808
+ }
809
+ toString() {
810
+ return `Number${this.inverse ? "Not" : ""}CloseTo`;
811
+ }
812
+ getExpectedType() {
813
+ return "number";
814
+ }
815
+ toAsymmetricMatcher() {
816
+ return [
817
+ this.toString(),
818
+ this.sample,
819
+ `(${pluralize("digit", this.precision)})`
820
+ ].join(" ");
821
+ }
822
+ }
823
+ const JestAsymmetricMatchers = (chai2, utils) => {
824
+ utils.addMethod(chai2.expect, "anything", () => new Anything());
825
+ utils.addMethod(chai2.expect, "any", (expected) => new Any(expected));
826
+ utils.addMethod(
827
+ chai2.expect,
828
+ "stringContaining",
829
+ (expected) => new StringContaining(expected)
830
+ );
831
+ utils.addMethod(
832
+ chai2.expect,
833
+ "objectContaining",
834
+ (expected) => new ObjectContaining(expected)
835
+ );
836
+ utils.addMethod(
837
+ chai2.expect,
838
+ "arrayContaining",
839
+ (expected) => new ArrayContaining(expected)
840
+ );
841
+ utils.addMethod(
842
+ chai2.expect,
843
+ "stringMatching",
844
+ (expected) => new StringMatching(expected)
845
+ );
846
+ utils.addMethod(
847
+ chai2.expect,
848
+ "closeTo",
849
+ (expected, precision) => new CloseTo(expected, precision)
850
+ );
851
+ chai2.expect.not = {
852
+ stringContaining: (expected) => new StringContaining(expected, true),
853
+ objectContaining: (expected) => new ObjectContaining(expected, true),
854
+ arrayContaining: (expected) => new ArrayContaining(expected, true),
855
+ stringMatching: (expected) => new StringMatching(expected, true),
856
+ closeTo: (expected, precision) => new CloseTo(expected, precision, true)
857
+ };
858
+ };
859
+ function recordAsyncExpect(test, promise) {
860
+ if (test && promise instanceof Promise) {
861
+ promise = promise.finally(() => {
862
+ const index2 = test.promises.indexOf(promise);
863
+ if (index2 !== -1) {
864
+ test.promises.splice(index2, 1);
865
+ }
866
+ });
867
+ if (!test.promises) {
868
+ test.promises = [];
869
+ }
870
+ test.promises.push(promise);
871
+ }
872
+ return promise;
873
+ }
874
+ function wrapSoft(utils, fn) {
875
+ return function(...args) {
876
+ var _a;
877
+ if (!utils.flag(this, "soft")) {
878
+ return fn.apply(this, args);
879
+ }
880
+ const test = utils.flag(this, "vitest-test");
881
+ if (!test) {
882
+ throw new Error("expect.soft() can only be used inside a test");
883
+ }
884
+ try {
885
+ return fn.apply(this, args);
886
+ } catch (err) {
887
+ test.result || (test.result = { state: "fail" });
888
+ test.result.state = "fail";
889
+ (_a = test.result).errors || (_a.errors = []);
890
+ test.result.errors.push(error.processError(err));
891
+ }
892
+ };
893
+ }
894
+ const JestChaiExpect = (chai2, utils) => {
895
+ const { AssertionError } = chai2;
896
+ const customTesters = getCustomEqualityTesters();
897
+ function def(name, fn) {
898
+ const addMethod = (n) => {
899
+ const softWrapper = wrapSoft(utils, fn);
900
+ utils.addMethod(chai2.Assertion.prototype, n, softWrapper);
901
+ utils.addMethod(
902
+ globalThis[JEST_MATCHERS_OBJECT].matchers,
903
+ n,
904
+ softWrapper
905
+ );
906
+ };
907
+ if (Array.isArray(name)) {
908
+ name.forEach((n) => addMethod(n));
909
+ } else {
910
+ addMethod(name);
911
+ }
912
+ }
913
+ ["throw", "throws", "Throw"].forEach((m) => {
914
+ utils.overwriteMethod(chai2.Assertion.prototype, m, (_super) => {
915
+ return function(...args) {
916
+ const promise = utils.flag(this, "promise");
917
+ const object = utils.flag(this, "object");
918
+ const isNot = utils.flag(this, "negate");
919
+ if (promise === "rejects") {
920
+ utils.flag(this, "object", () => {
921
+ throw object;
922
+ });
923
+ } else if (promise === "resolves" && typeof object !== "function") {
924
+ if (!isNot) {
925
+ const message = utils.flag(this, "message") || "expected promise to throw an error, but it didn't";
926
+ const error2 = {
927
+ showDiff: false
928
+ };
929
+ throw new AssertionError(message, error2, utils.flag(this, "ssfi"));
930
+ } else {
931
+ return;
932
+ }
933
+ }
934
+ _super.apply(this, args);
935
+ };
936
+ });
937
+ });
938
+ def("withTest", function(test) {
939
+ utils.flag(this, "vitest-test", test);
940
+ return this;
941
+ });
942
+ def("toEqual", function(expected) {
943
+ const actual = utils.flag(this, "object");
944
+ const equal = equals(actual, expected, [
945
+ ...customTesters,
946
+ iterableEquality
947
+ ]);
948
+ return this.assert(
949
+ equal,
950
+ "expected #{this} to deeply equal #{exp}",
951
+ "expected #{this} to not deeply equal #{exp}",
952
+ expected,
953
+ actual
954
+ );
955
+ });
956
+ def("toStrictEqual", function(expected) {
957
+ const obj = utils.flag(this, "object");
958
+ const equal = equals(
959
+ obj,
960
+ expected,
961
+ [
962
+ ...customTesters,
963
+ iterableEquality,
964
+ typeEquality,
965
+ sparseArrayEquality,
966
+ arrayBufferEquality
967
+ ],
968
+ true
969
+ );
970
+ return this.assert(
971
+ equal,
972
+ "expected #{this} to strictly equal #{exp}",
973
+ "expected #{this} to not strictly equal #{exp}",
974
+ expected,
975
+ obj
976
+ );
977
+ });
978
+ def("toBe", function(expected) {
979
+ const actual = this._obj;
980
+ const pass = Object.is(actual, expected);
981
+ let deepEqualityName = "";
982
+ if (!pass) {
983
+ const toStrictEqualPass = equals(
984
+ actual,
985
+ expected,
986
+ [
987
+ ...customTesters,
988
+ iterableEquality,
989
+ typeEquality,
990
+ sparseArrayEquality,
991
+ arrayBufferEquality
992
+ ],
993
+ true
994
+ );
995
+ if (toStrictEqualPass) {
996
+ deepEqualityName = "toStrictEqual";
997
+ } else {
998
+ const toEqualPass = equals(actual, expected, [
999
+ ...customTesters,
1000
+ iterableEquality
1001
+ ]);
1002
+ if (toEqualPass) {
1003
+ deepEqualityName = "toEqual";
1004
+ }
1005
+ }
1006
+ }
1007
+ return this.assert(
1008
+ pass,
1009
+ generateToBeMessage(deepEqualityName),
1010
+ "expected #{this} not to be #{exp} // Object.is equality",
1011
+ expected,
1012
+ actual
1013
+ );
1014
+ });
1015
+ def("toMatchObject", function(expected) {
1016
+ const actual = this._obj;
1017
+ const pass = equals(actual, expected, [
1018
+ ...customTesters,
1019
+ iterableEquality,
1020
+ subsetEquality
1021
+ ]);
1022
+ const isNot = utils.flag(this, "negate");
1023
+ const { subset: actualSubset, stripped } = getObjectSubset(
1024
+ actual,
1025
+ expected
1026
+ );
1027
+ if (pass && isNot || !pass && !isNot) {
1028
+ const msg = utils.getMessage(this, [
1029
+ pass,
1030
+ "expected #{this} to match object #{exp}",
1031
+ "expected #{this} to not match object #{exp}",
1032
+ expected,
1033
+ actualSubset,
1034
+ false
1035
+ ]);
1036
+ const message = stripped === 0 ? msg : `${msg}
1037
+ (${stripped} matching ${stripped === 1 ? "property" : "properties"} omitted from actual)`;
1038
+ throw new AssertionError(message, {
1039
+ showDiff: true,
1040
+ expected,
1041
+ actual: actualSubset
1042
+ });
1043
+ }
1044
+ });
1045
+ def("toMatch", function(expected) {
1046
+ const actual = this._obj;
1047
+ if (typeof actual !== "string") {
1048
+ throw new TypeError(
1049
+ `.toMatch() expects to receive a string, but got ${typeof actual}`
1050
+ );
1051
+ }
1052
+ return this.assert(
1053
+ typeof expected === "string" ? actual.includes(expected) : actual.match(expected),
1054
+ `expected #{this} to match #{exp}`,
1055
+ `expected #{this} not to match #{exp}`,
1056
+ expected,
1057
+ actual
1058
+ );
1059
+ });
1060
+ def("toContain", function(item) {
1061
+ const actual = this._obj;
1062
+ if (typeof Node !== "undefined" && actual instanceof Node) {
1063
+ if (!(item instanceof Node)) {
1064
+ throw new TypeError(
1065
+ `toContain() expected a DOM node as the argument, but got ${typeof item}`
1066
+ );
1067
+ }
1068
+ return this.assert(
1069
+ actual.contains(item),
1070
+ "expected #{this} to contain element #{exp}",
1071
+ "expected #{this} not to contain element #{exp}",
1072
+ item,
1073
+ actual
1074
+ );
1075
+ }
1076
+ if (typeof DOMTokenList !== "undefined" && actual instanceof DOMTokenList) {
1077
+ helpers.assertTypes(item, "class name", ["string"]);
1078
+ const isNot = utils.flag(this, "negate");
1079
+ const expectedClassList = isNot ? actual.value.replace(item, "").trim() : `${actual.value} ${item}`;
1080
+ return this.assert(
1081
+ actual.contains(item),
1082
+ `expected "${actual.value}" to contain "${item}"`,
1083
+ `expected "${actual.value}" not to contain "${item}"`,
1084
+ expectedClassList,
1085
+ actual.value
1086
+ );
1087
+ }
1088
+ if (typeof actual === "string" && typeof item === "string") {
1089
+ return this.assert(
1090
+ actual.includes(item),
1091
+ `expected #{this} to contain #{exp}`,
1092
+ `expected #{this} not to contain #{exp}`,
1093
+ item,
1094
+ actual
1095
+ );
1096
+ }
1097
+ if (actual != null && typeof actual !== "string") {
1098
+ utils.flag(this, "object", Array.from(actual));
1099
+ }
1100
+ return this.contain(item);
1101
+ });
1102
+ def("toContainEqual", function(expected) {
1103
+ const obj = utils.flag(this, "object");
1104
+ const index2 = Array.from(obj).findIndex((item) => {
1105
+ return equals(item, expected, customTesters);
1106
+ });
1107
+ this.assert(
1108
+ index2 !== -1,
1109
+ "expected #{this} to deep equally contain #{exp}",
1110
+ "expected #{this} to not deep equally contain #{exp}",
1111
+ expected
1112
+ );
1113
+ });
1114
+ def("toBeTruthy", function() {
1115
+ const obj = utils.flag(this, "object");
1116
+ this.assert(
1117
+ Boolean(obj),
1118
+ "expected #{this} to be truthy",
1119
+ "expected #{this} to not be truthy",
1120
+ obj,
1121
+ false
1122
+ );
1123
+ });
1124
+ def("toBeFalsy", function() {
1125
+ const obj = utils.flag(this, "object");
1126
+ this.assert(
1127
+ !obj,
1128
+ "expected #{this} to be falsy",
1129
+ "expected #{this} to not be falsy",
1130
+ obj,
1131
+ false
1132
+ );
1133
+ });
1134
+ def("toBeGreaterThan", function(expected) {
1135
+ const actual = this._obj;
1136
+ helpers.assertTypes(actual, "actual", ["number", "bigint"]);
1137
+ helpers.assertTypes(expected, "expected", ["number", "bigint"]);
1138
+ return this.assert(
1139
+ actual > expected,
1140
+ `expected ${actual} to be greater than ${expected}`,
1141
+ `expected ${actual} to be not greater than ${expected}`,
1142
+ actual,
1143
+ expected,
1144
+ false
1145
+ );
1146
+ });
1147
+ def("toBeGreaterThanOrEqual", function(expected) {
1148
+ const actual = this._obj;
1149
+ helpers.assertTypes(actual, "actual", ["number", "bigint"]);
1150
+ helpers.assertTypes(expected, "expected", ["number", "bigint"]);
1151
+ return this.assert(
1152
+ actual >= expected,
1153
+ `expected ${actual} to be greater than or equal to ${expected}`,
1154
+ `expected ${actual} to be not greater than or equal to ${expected}`,
1155
+ actual,
1156
+ expected,
1157
+ false
1158
+ );
1159
+ });
1160
+ def("toBeLessThan", function(expected) {
1161
+ const actual = this._obj;
1162
+ helpers.assertTypes(actual, "actual", ["number", "bigint"]);
1163
+ helpers.assertTypes(expected, "expected", ["number", "bigint"]);
1164
+ return this.assert(
1165
+ actual < expected,
1166
+ `expected ${actual} to be less than ${expected}`,
1167
+ `expected ${actual} to be not less than ${expected}`,
1168
+ actual,
1169
+ expected,
1170
+ false
1171
+ );
1172
+ });
1173
+ def("toBeLessThanOrEqual", function(expected) {
1174
+ const actual = this._obj;
1175
+ helpers.assertTypes(actual, "actual", ["number", "bigint"]);
1176
+ helpers.assertTypes(expected, "expected", ["number", "bigint"]);
1177
+ return this.assert(
1178
+ actual <= expected,
1179
+ `expected ${actual} to be less than or equal to ${expected}`,
1180
+ `expected ${actual} to be not less than or equal to ${expected}`,
1181
+ actual,
1182
+ expected,
1183
+ false
1184
+ );
1185
+ });
1186
+ def("toBeNaN", function() {
1187
+ return this.be.NaN;
1188
+ });
1189
+ def("toBeUndefined", function() {
1190
+ return this.be.undefined;
1191
+ });
1192
+ def("toBeNull", function() {
1193
+ return this.be.null;
1194
+ });
1195
+ def("toBeDefined", function() {
1196
+ const negate = utils.flag(this, "negate");
1197
+ utils.flag(this, "negate", false);
1198
+ if (negate) {
1199
+ return this.be.undefined;
1200
+ }
1201
+ return this.not.be.undefined;
1202
+ });
1203
+ def(
1204
+ "toBeTypeOf",
1205
+ function(expected) {
1206
+ const actual = typeof this._obj;
1207
+ const equal = expected === actual;
1208
+ return this.assert(
1209
+ equal,
1210
+ "expected #{this} to be type of #{exp}",
1211
+ "expected #{this} not to be type of #{exp}",
1212
+ expected,
1213
+ actual
1214
+ );
1215
+ }
1216
+ );
1217
+ def("toBeInstanceOf", function(obj) {
1218
+ return this.instanceOf(obj);
1219
+ });
1220
+ def("toHaveLength", function(length) {
1221
+ return this.have.length(length);
1222
+ });
1223
+ def(
1224
+ "toHaveProperty",
1225
+ function(...args) {
1226
+ if (Array.isArray(args[0])) {
1227
+ args[0] = args[0].map((key) => String(key).replace(/([.[\]])/g, "\\$1")).join(".");
1228
+ }
1229
+ const actual = this._obj;
1230
+ const [propertyName, expected] = args;
1231
+ const getValue = () => {
1232
+ const hasOwn = Object.prototype.hasOwnProperty.call(
1233
+ actual,
1234
+ propertyName
1235
+ );
1236
+ if (hasOwn) {
1237
+ return { value: actual[propertyName], exists: true };
1238
+ }
1239
+ return utils.getPathInfo(actual, propertyName);
1240
+ };
1241
+ const { value, exists } = getValue();
1242
+ const pass = exists && (args.length === 1 || equals(expected, value, customTesters));
1243
+ const valueString = args.length === 1 ? "" : ` with value ${utils.objDisplay(expected)}`;
1244
+ return this.assert(
1245
+ pass,
1246
+ `expected #{this} to have property "${propertyName}"${valueString}`,
1247
+ `expected #{this} to not have property "${propertyName}"${valueString}`,
1248
+ expected,
1249
+ exists ? value : void 0
1250
+ );
1251
+ }
1252
+ );
1253
+ def("toBeCloseTo", function(received, precision = 2) {
1254
+ const expected = this._obj;
1255
+ let pass = false;
1256
+ let expectedDiff = 0;
1257
+ let receivedDiff = 0;
1258
+ if (received === Number.POSITIVE_INFINITY && expected === Number.POSITIVE_INFINITY) {
1259
+ pass = true;
1260
+ } else if (received === Number.NEGATIVE_INFINITY && expected === Number.NEGATIVE_INFINITY) {
1261
+ pass = true;
1262
+ } else {
1263
+ expectedDiff = 10 ** -precision / 2;
1264
+ receivedDiff = Math.abs(expected - received);
1265
+ pass = receivedDiff < expectedDiff;
1266
+ }
1267
+ return this.assert(
1268
+ pass,
1269
+ `expected #{this} to be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
1270
+ `expected #{this} to not be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
1271
+ received,
1272
+ expected,
1273
+ false
1274
+ );
1275
+ });
1276
+ function assertIsMock(assertion) {
1277
+ if (!index.isMockFunction(assertion._obj)) {
1278
+ throw new TypeError(
1279
+ `${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`
1280
+ );
1281
+ }
1282
+ }
1283
+ function getSpy(assertion) {
1284
+ assertIsMock(assertion);
1285
+ return assertion._obj;
1286
+ }
1287
+ def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
1288
+ const spy = getSpy(this);
1289
+ const spyName = spy.getMockName();
1290
+ const callCount = spy.mock.calls.length;
1291
+ return this.assert(
1292
+ callCount === number,
1293
+ `expected "${spyName}" to be called #{exp} times, but got ${callCount} times`,
1294
+ `expected "${spyName}" to not be called #{exp} times`,
1295
+ number,
1296
+ callCount,
1297
+ false
1298
+ );
1299
+ });
1300
+ def("toHaveBeenCalledOnce", function() {
1301
+ const spy = getSpy(this);
1302
+ const spyName = spy.getMockName();
1303
+ const callCount = spy.mock.calls.length;
1304
+ return this.assert(
1305
+ callCount === 1,
1306
+ `expected "${spyName}" to be called once, but got ${callCount} times`,
1307
+ `expected "${spyName}" to not be called once`,
1308
+ 1,
1309
+ callCount,
1310
+ false
1311
+ );
1312
+ });
1313
+ def(["toHaveBeenCalled", "toBeCalled"], function() {
1314
+ const spy = getSpy(this);
1315
+ const spyName = spy.getMockName();
1316
+ const callCount = spy.mock.calls.length;
1317
+ const called = callCount > 0;
1318
+ const isNot = utils.flag(this, "negate");
1319
+ let msg = utils.getMessage(this, [
1320
+ called,
1321
+ `expected "${spyName}" to be called at least once`,
1322
+ `expected "${spyName}" to not be called at all, but actually been called ${callCount} times`,
1323
+ true,
1324
+ called
1325
+ ]);
1326
+ if (called && isNot) {
1327
+ msg = formatCalls(spy, msg);
1328
+ }
1329
+ if (called && isNot || !called && !isNot) {
1330
+ throw new AssertionError(msg);
1331
+ }
1332
+ });
1333
+ def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
1334
+ const spy = getSpy(this);
1335
+ const spyName = spy.getMockName();
1336
+ const pass = spy.mock.calls.some(
1337
+ (callArg) => equals(callArg, args, [...customTesters, iterableEquality])
1338
+ );
1339
+ const isNot = utils.flag(this, "negate");
1340
+ const msg = utils.getMessage(this, [
1341
+ pass,
1342
+ `expected "${spyName}" to be called with arguments: #{exp}`,
1343
+ `expected "${spyName}" to not be called with arguments: #{exp}`,
1344
+ args
1345
+ ]);
1346
+ if (pass && isNot || !pass && !isNot) {
1347
+ throw new AssertionError(formatCalls(spy, msg, args));
1348
+ }
1349
+ });
1350
+ def(
1351
+ ["toHaveBeenNthCalledWith", "nthCalledWith"],
1352
+ function(times, ...args) {
1353
+ const spy = getSpy(this);
1354
+ const spyName = spy.getMockName();
1355
+ const nthCall = spy.mock.calls[times - 1];
1356
+ const callCount = spy.mock.calls.length;
1357
+ const isCalled = times <= callCount;
1358
+ this.assert(
1359
+ equals(nthCall, args, [...customTesters, iterableEquality]),
1360
+ `expected ${ordinalOf(
1361
+ times
1362
+ )} "${spyName}" call to have been called with #{exp}${isCalled ? `` : `, but called only ${callCount} times`}`,
1363
+ `expected ${ordinalOf(
1364
+ times
1365
+ )} "${spyName}" call to not have been called with #{exp}`,
1366
+ args,
1367
+ nthCall,
1368
+ isCalled
1369
+ );
1370
+ }
1371
+ );
1372
+ def(
1373
+ ["toHaveBeenLastCalledWith", "lastCalledWith"],
1374
+ function(...args) {
1375
+ const spy = getSpy(this);
1376
+ const spyName = spy.getMockName();
1377
+ const lastCall = spy.mock.calls[spy.mock.calls.length - 1];
1378
+ this.assert(
1379
+ equals(lastCall, args, [...customTesters, iterableEquality]),
1380
+ `expected last "${spyName}" call to have been called with #{exp}`,
1381
+ `expected last "${spyName}" call to not have been called with #{exp}`,
1382
+ args,
1383
+ lastCall
1384
+ );
1385
+ }
1386
+ );
1387
+ def(
1388
+ ["toThrow", "toThrowError"],
1389
+ function(expected) {
1390
+ if (typeof expected === "string" || typeof expected === "undefined" || expected instanceof RegExp) {
1391
+ return this.throws(expected);
1392
+ }
1393
+ const obj = this._obj;
1394
+ const promise = utils.flag(this, "promise");
1395
+ const isNot = utils.flag(this, "negate");
1396
+ let thrown = null;
1397
+ if (promise === "rejects") {
1398
+ thrown = obj;
1399
+ } else if (promise === "resolves" && typeof obj !== "function") {
1400
+ if (!isNot) {
1401
+ const message = utils.flag(this, "message") || "expected promise to throw an error, but it didn't";
1402
+ const error2 = {
1403
+ showDiff: false
1404
+ };
1405
+ throw new AssertionError(message, error2, utils.flag(this, "ssfi"));
1406
+ } else {
1407
+ return;
1408
+ }
1409
+ } else {
1410
+ let isThrow = false;
1411
+ try {
1412
+ obj();
1413
+ } catch (err) {
1414
+ isThrow = true;
1415
+ thrown = err;
1416
+ }
1417
+ if (!isThrow && !isNot) {
1418
+ const message = utils.flag(this, "message") || "expected function to throw an error, but it didn't";
1419
+ const error2 = {
1420
+ showDiff: false
1421
+ };
1422
+ throw new AssertionError(message, error2, utils.flag(this, "ssfi"));
1423
+ }
1424
+ }
1425
+ if (typeof expected === "function") {
1426
+ const name = expected.name || expected.prototype.constructor.name;
1427
+ return this.assert(
1428
+ thrown && thrown instanceof expected,
1429
+ `expected error to be instance of ${name}`,
1430
+ `expected error not to be instance of ${name}`,
1431
+ expected,
1432
+ thrown
1433
+ );
1434
+ }
1435
+ if (expected instanceof Error) {
1436
+ return this.assert(
1437
+ thrown && expected.message === thrown.message,
1438
+ `expected error to have message: ${expected.message}`,
1439
+ `expected error not to have message: ${expected.message}`,
1440
+ expected.message,
1441
+ thrown && thrown.message
1442
+ );
1443
+ }
1444
+ if (typeof expected === "object" && "asymmetricMatch" in expected && typeof expected.asymmetricMatch === "function") {
1445
+ const matcher = expected;
1446
+ return this.assert(
1447
+ thrown && matcher.asymmetricMatch(thrown),
1448
+ "expected error to match asymmetric matcher",
1449
+ "expected error not to match asymmetric matcher",
1450
+ matcher,
1451
+ thrown
1452
+ );
1453
+ }
1454
+ throw new Error(
1455
+ `"toThrow" expects string, RegExp, function, Error instance or asymmetric matcher, got "${typeof expected}"`
1456
+ );
1457
+ }
1458
+ );
1459
+ [
1460
+ {
1461
+ name: "toHaveResolved",
1462
+ condition: (spy) => spy.mock.settledResults.length > 0 && spy.mock.settledResults.some(({ type }) => type === "fulfilled"),
1463
+ action: "resolved"
1464
+ },
1465
+ {
1466
+ name: ["toHaveReturned", "toReturn"],
1467
+ condition: (spy) => spy.mock.calls.length > 0 && spy.mock.results.some(({ type }) => type !== "throw"),
1468
+ action: "called"
1469
+ }
1470
+ ].forEach(({ name, condition, action }) => {
1471
+ def(name, function() {
1472
+ const spy = getSpy(this);
1473
+ const spyName = spy.getMockName();
1474
+ const pass = condition(spy);
1475
+ this.assert(
1476
+ pass,
1477
+ `expected "${spyName}" to be successfully ${action} at least once`,
1478
+ `expected "${spyName}" to not be successfully ${action}`,
1479
+ pass,
1480
+ !pass,
1481
+ false
1482
+ );
1483
+ });
1484
+ });
1485
+ [
1486
+ {
1487
+ name: "toHaveResolvedTimes",
1488
+ condition: (spy, times) => spy.mock.settledResults.reduce(
1489
+ (s, { type }) => type === "fulfilled" ? ++s : s,
1490
+ 0
1491
+ ) === times,
1492
+ action: "resolved"
1493
+ },
1494
+ {
1495
+ name: ["toHaveReturnedTimes", "toReturnTimes"],
1496
+ condition: (spy, times) => spy.mock.results.reduce(
1497
+ (s, { type }) => type === "throw" ? s : ++s,
1498
+ 0
1499
+ ) === times,
1500
+ action: "called"
1501
+ }
1502
+ ].forEach(({ name, condition, action }) => {
1503
+ def(name, function(times) {
1504
+ const spy = getSpy(this);
1505
+ const spyName = spy.getMockName();
1506
+ const pass = condition(spy, times);
1507
+ this.assert(
1508
+ pass,
1509
+ `expected "${spyName}" to be successfully ${action} ${times} times`,
1510
+ `expected "${spyName}" to not be successfully ${action} ${times} times`,
1511
+ `expected resolved times: ${times}`,
1512
+ `received resolved times: ${pass}`,
1513
+ false
1514
+ );
1515
+ });
1516
+ });
1517
+ [
1518
+ {
1519
+ name: "toHaveResolvedWith",
1520
+ condition: (spy, value) => spy.mock.settledResults.some(
1521
+ ({ type, value: result }) => type === "fulfilled" && equals(value, result)
1522
+ ),
1523
+ action: "resolve"
1524
+ },
1525
+ {
1526
+ name: ["toHaveReturnedWith", "toReturnWith"],
1527
+ condition: (spy, value) => spy.mock.results.some(
1528
+ ({ type, value: result }) => type === "return" && equals(value, result)
1529
+ ),
1530
+ action: "return"
1531
+ }
1532
+ ].forEach(({ name, condition, action }) => {
1533
+ def(name, function(value) {
1534
+ const spy = getSpy(this);
1535
+ const pass = condition(spy, value);
1536
+ const isNot = utils.flag(this, "negate");
1537
+ if (pass && isNot || !pass && !isNot) {
1538
+ const spyName = spy.getMockName();
1539
+ const msg = utils.getMessage(this, [
1540
+ pass,
1541
+ `expected "${spyName}" to ${action} with: #{exp} at least once`,
1542
+ `expected "${spyName}" to not ${action} with: #{exp}`,
1543
+ value
1544
+ ]);
1545
+ const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1546
+ throw new AssertionError(formatReturns(spy, results, msg, value));
1547
+ }
1548
+ });
1549
+ });
1550
+ [
1551
+ {
1552
+ name: "toHaveLastResolvedWith",
1553
+ condition: (spy, value) => {
1554
+ const result = spy.mock.settledResults[spy.mock.settledResults.length - 1];
1555
+ return result && result.type === "fulfilled" && equals(result.value, value);
1556
+ },
1557
+ action: "resolve"
1558
+ },
1559
+ {
1560
+ name: ["toHaveLastReturnedWith", "lastReturnedWith"],
1561
+ condition: (spy, value) => {
1562
+ const result = spy.mock.results[spy.mock.results.length - 1];
1563
+ return result && result.type === "return" && equals(result.value, value);
1564
+ },
1565
+ action: "return"
1566
+ }
1567
+ ].forEach(({ name, condition, action }) => {
1568
+ def(name, function(value) {
1569
+ const spy = getSpy(this);
1570
+ const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1571
+ const result = results[results.length - 1];
1572
+ const spyName = spy.getMockName();
1573
+ this.assert(
1574
+ condition(spy, value),
1575
+ `expected last "${spyName}" call to ${action} #{exp}`,
1576
+ `expected last "${spyName}" call to not ${action} #{exp}`,
1577
+ value,
1578
+ result == null ? void 0 : result.value
1579
+ );
1580
+ });
1581
+ });
1582
+ [
1583
+ {
1584
+ name: "toHaveNthResolvedWith",
1585
+ condition: (spy, index2, value) => {
1586
+ const result = spy.mock.settledResults[index2 - 1];
1587
+ return result && result.type === "fulfilled" && equals(result.value, value);
1588
+ },
1589
+ action: "resolve"
1590
+ },
1591
+ {
1592
+ name: ["toHaveNthReturnedWith", "nthReturnedWith"],
1593
+ condition: (spy, index2, value) => {
1594
+ const result = spy.mock.results[index2 - 1];
1595
+ return result && result.type === "return" && equals(result.value, value);
1596
+ },
1597
+ action: "return"
1598
+ }
1599
+ ].forEach(({ name, condition, action }) => {
1600
+ def(name, function(nthCall, value) {
1601
+ const spy = getSpy(this);
1602
+ const spyName = spy.getMockName();
1603
+ const results = action === "return" ? spy.mock.results : spy.mock.settledResults;
1604
+ const result = results[nthCall - 1];
1605
+ const ordinalCall = `${ordinalOf(nthCall)} call`;
1606
+ this.assert(
1607
+ condition(spy, nthCall, value),
1608
+ `expected ${ordinalCall} "${spyName}" call to ${action} #{exp}`,
1609
+ `expected ${ordinalCall} "${spyName}" call to not ${action} #{exp}`,
1610
+ value,
1611
+ result == null ? void 0 : result.value
1612
+ );
1613
+ });
1614
+ });
1615
+ def("toSatisfy", function(matcher, message) {
1616
+ return this.be.satisfy(matcher, message);
1617
+ });
1618
+ def("withContext", function(context) {
1619
+ for (const key in context) {
1620
+ utils.flag(this, key, context[key]);
1621
+ }
1622
+ return this;
1623
+ });
1624
+ utils.addProperty(
1625
+ chai2.Assertion.prototype,
1626
+ "resolves",
1627
+ function __VITEST_RESOLVES__() {
1628
+ const error2 = new Error("resolves");
1629
+ utils.flag(this, "promise", "resolves");
1630
+ utils.flag(this, "error", error2);
1631
+ const test = utils.flag(this, "vitest-test");
1632
+ const obj = utils.flag(this, "object");
1633
+ if (utils.flag(this, "poll")) {
1634
+ throw new SyntaxError(
1635
+ `expect.poll() is not supported in combination with .resolves`
1636
+ );
1637
+ }
1638
+ if (typeof (obj == null ? void 0 : obj.then) !== "function") {
1639
+ throw new TypeError(
1640
+ `You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`
1641
+ );
1642
+ }
1643
+ const proxy = new Proxy(this, {
1644
+ get: (target, key, receiver) => {
1645
+ const result = Reflect.get(target, key, receiver);
1646
+ if (typeof result !== "function") {
1647
+ return result instanceof chai2.Assertion ? proxy : result;
1648
+ }
1649
+ return (...args) => {
1650
+ const promise = obj.then(
1651
+ (value) => {
1652
+ utils.flag(this, "object", value);
1653
+ return result.call(this, ...args);
1654
+ },
1655
+ (err) => {
1656
+ const _error = new AssertionError(
1657
+ `promise rejected "${utils.inspect(
1658
+ err
1659
+ )}" instead of resolving`,
1660
+ { showDiff: false }
1661
+ );
1662
+ _error.cause = err;
1663
+ _error.stack = error2.stack.replace(
1664
+ error2.message,
1665
+ _error.message
1666
+ );
1667
+ throw _error;
1668
+ }
1669
+ );
1670
+ return recordAsyncExpect(test, promise);
1671
+ };
1672
+ }
1673
+ });
1674
+ return proxy;
1675
+ }
1676
+ );
1677
+ utils.addProperty(
1678
+ chai2.Assertion.prototype,
1679
+ "rejects",
1680
+ function __VITEST_REJECTS__() {
1681
+ const error2 = new Error("rejects");
1682
+ utils.flag(this, "promise", "rejects");
1683
+ utils.flag(this, "error", error2);
1684
+ const test = utils.flag(this, "vitest-test");
1685
+ const obj = utils.flag(this, "object");
1686
+ const wrapper = typeof obj === "function" ? obj() : obj;
1687
+ if (utils.flag(this, "poll")) {
1688
+ throw new SyntaxError(
1689
+ `expect.poll() is not supported in combination with .rejects`
1690
+ );
1691
+ }
1692
+ if (typeof (wrapper == null ? void 0 : wrapper.then) !== "function") {
1693
+ throw new TypeError(
1694
+ `You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`
1695
+ );
1696
+ }
1697
+ const proxy = new Proxy(this, {
1698
+ get: (target, key, receiver) => {
1699
+ const result = Reflect.get(target, key, receiver);
1700
+ if (typeof result !== "function") {
1701
+ return result instanceof chai2.Assertion ? proxy : result;
1702
+ }
1703
+ return (...args) => {
1704
+ const promise = wrapper.then(
1705
+ (value) => {
1706
+ const _error = new AssertionError(
1707
+ `promise resolved "${utils.inspect(
1708
+ value
1709
+ )}" instead of rejecting`,
1710
+ {
1711
+ showDiff: true,
1712
+ expected: new Error("rejected promise"),
1713
+ actual: value
1714
+ }
1715
+ );
1716
+ _error.stack = error2.stack.replace(
1717
+ error2.message,
1718
+ _error.message
1719
+ );
1720
+ throw _error;
1721
+ },
1722
+ (err) => {
1723
+ utils.flag(this, "object", err);
1724
+ return result.call(this, ...args);
1725
+ }
1726
+ );
1727
+ return recordAsyncExpect(test, promise);
1728
+ };
1729
+ }
1730
+ });
1731
+ return proxy;
1732
+ }
1733
+ );
1734
+ };
1735
+ function ordinalOf(i) {
1736
+ const j = i % 10;
1737
+ const k = i % 100;
1738
+ if (j === 1 && k !== 11) {
1739
+ return `${i}st`;
1740
+ }
1741
+ if (j === 2 && k !== 12) {
1742
+ return `${i}nd`;
1743
+ }
1744
+ if (j === 3 && k !== 13) {
1745
+ return `${i}rd`;
1746
+ }
1747
+ return `${i}th`;
1748
+ }
1749
+ function formatCalls(spy, msg, showActualCall) {
1750
+ if (spy.mock.calls) {
1751
+ msg += browser.default.gray(
1752
+ `
1753
+
1754
+ Received:
1755
+
1756
+ ${spy.mock.calls.map((callArg, i) => {
1757
+ let methodCall = browser.default.bold(
1758
+ ` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
1759
+
1760
+ `
1761
+ );
1762
+ if (showActualCall) {
1763
+ methodCall += diff.diff(showActualCall, callArg, {
1764
+ omitAnnotationLines: true
1765
+ });
1766
+ } else {
1767
+ methodCall += chunkDisplay.s(callArg).split("\n").map((line) => ` ${line}`).join("\n");
1768
+ }
1769
+ methodCall += "\n";
1770
+ return methodCall;
1771
+ }).join("\n")}`
1772
+ );
1773
+ }
1774
+ msg += browser.default.gray(
1775
+ `
1776
+
1777
+ Number of calls: ${browser.default.bold(spy.mock.calls.length)}
1778
+ `
1779
+ );
1780
+ return msg;
1781
+ }
1782
+ function formatReturns(spy, results, msg, showActualReturn) {
1783
+ msg += browser.default.gray(
1784
+ `
1785
+
1786
+ Received:
1787
+
1788
+ ${results.map((callReturn, i) => {
1789
+ let methodCall = browser.default.bold(
1790
+ ` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
1791
+
1792
+ `
1793
+ );
1794
+ if (showActualReturn) {
1795
+ methodCall += diff.diff(showActualReturn, callReturn.value, {
1796
+ omitAnnotationLines: true
1797
+ });
1798
+ } else {
1799
+ methodCall += chunkDisplay.s(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
1800
+ }
1801
+ methodCall += "\n";
1802
+ return methodCall;
1803
+ }).join("\n")}`
1804
+ );
1805
+ msg += browser.default.gray(
1806
+ `
1807
+
1808
+ Number of calls: ${browser.default.bold(spy.mock.calls.length)}
1809
+ `
1810
+ );
1811
+ return msg;
1812
+ }
1813
+ function getMatcherState(assertion, expect) {
1814
+ const obj = assertion._obj;
1815
+ const isNot = chai.util.flag(assertion, "negate");
1816
+ const promise = chai.util.flag(assertion, "promise") || "";
1817
+ const jestUtils = {
1818
+ ...getMatcherUtils(),
1819
+ diff: diff.diff,
1820
+ stringify: chunkDisplay.s,
1821
+ iterableEquality,
1822
+ subsetEquality
1823
+ };
1824
+ const matcherState = {
1825
+ ...getState(expect),
1826
+ customTesters: getCustomEqualityTesters(),
1827
+ isNot,
1828
+ utils: jestUtils,
1829
+ promise,
1830
+ equals,
1831
+ // needed for built-in jest-snapshots, but we don't use it
1832
+ suppressedErrors: [],
1833
+ soft: chai.util.flag(assertion, "soft"),
1834
+ poll: chai.util.flag(assertion, "poll")
1835
+ };
1836
+ return {
1837
+ state: matcherState,
1838
+ isNot,
1839
+ obj
1840
+ };
1841
+ }
1842
+ class JestExtendError extends Error {
1843
+ constructor(message, actual, expected) {
1844
+ super(message);
1845
+ this.actual = actual;
1846
+ this.expected = expected;
1847
+ }
1848
+ }
1849
+ function JestExtendPlugin(c, expect, matchers) {
1850
+ return (_, utils) => {
1851
+ Object.entries(matchers).forEach(
1852
+ ([expectAssertionName, expectAssertion]) => {
1853
+ function expectWrapper(...args) {
1854
+ const { state, isNot, obj } = getMatcherState(this, expect);
1855
+ const result = expectAssertion.call(state, obj, ...args);
1856
+ if (result && typeof result === "object" && result instanceof Promise) {
1857
+ return result.then(({ pass: pass2, message: message2, actual: actual2, expected: expected2 }) => {
1858
+ if (pass2 && isNot || !pass2 && !isNot) {
1859
+ throw new JestExtendError(message2(), actual2, expected2);
1860
+ }
1861
+ });
1862
+ }
1863
+ const { pass, message, actual, expected } = result;
1864
+ if (pass && isNot || !pass && !isNot) {
1865
+ throw new JestExtendError(message(), actual, expected);
1866
+ }
1867
+ }
1868
+ const softWrapper = wrapSoft(utils, expectWrapper);
1869
+ utils.addMethod(
1870
+ globalThis[JEST_MATCHERS_OBJECT].matchers,
1871
+ expectAssertionName,
1872
+ softWrapper
1873
+ );
1874
+ utils.addMethod(
1875
+ c.Assertion.prototype,
1876
+ expectAssertionName,
1877
+ softWrapper
1878
+ );
1879
+ class CustomMatcher extends AsymmetricMatcher {
1880
+ constructor(inverse = false, ...sample) {
1881
+ super(sample, inverse);
1882
+ }
1883
+ asymmetricMatch(other) {
1884
+ const { pass } = expectAssertion.call(
1885
+ this.getMatcherContext(expect),
1886
+ other,
1887
+ ...this.sample
1888
+ );
1889
+ return this.inverse ? !pass : pass;
1890
+ }
1891
+ toString() {
1892
+ return `${this.inverse ? "not." : ""}${expectAssertionName}`;
1893
+ }
1894
+ getExpectedType() {
1895
+ return "any";
1896
+ }
1897
+ toAsymmetricMatcher() {
1898
+ return `${this.toString()}<${this.sample.map(String).join(", ")}>`;
1899
+ }
1900
+ }
1901
+ const customMatcher = (...sample) => new CustomMatcher(false, ...sample);
1902
+ Object.defineProperty(expect, expectAssertionName, {
1903
+ configurable: true,
1904
+ enumerable: true,
1905
+ value: customMatcher,
1906
+ writable: true
1907
+ });
1908
+ Object.defineProperty(expect.not, expectAssertionName, {
1909
+ configurable: true,
1910
+ enumerable: true,
1911
+ value: (...sample) => new CustomMatcher(true, ...sample),
1912
+ writable: true
1913
+ });
1914
+ Object.defineProperty(
1915
+ globalThis[ASYMMETRIC_MATCHERS_OBJECT],
1916
+ expectAssertionName,
1917
+ {
1918
+ configurable: true,
1919
+ enumerable: true,
1920
+ value: customMatcher,
1921
+ writable: true
1922
+ }
1923
+ );
1924
+ }
1925
+ );
1926
+ };
1927
+ }
1928
+ const JestExtend = (chai$1, utils) => {
1929
+ utils.addMethod(
1930
+ chai$1.expect,
1931
+ "extend",
1932
+ (expect, expects) => {
1933
+ chai.use(JestExtendPlugin(chai$1, expect, expects));
1934
+ }
1935
+ );
1936
+ };
1937
+ exports.ASYMMETRIC_MATCHERS_OBJECT = ASYMMETRIC_MATCHERS_OBJECT;
1938
+ exports.Any = Any;
1939
+ exports.Anything = Anything;
1940
+ exports.ArrayContaining = ArrayContaining;
1941
+ exports.AsymmetricMatcher = AsymmetricMatcher;
1942
+ exports.GLOBAL_EXPECT = GLOBAL_EXPECT;
1943
+ exports.JEST_MATCHERS_OBJECT = JEST_MATCHERS_OBJECT;
1944
+ exports.JestAsymmetricMatchers = JestAsymmetricMatchers;
1945
+ exports.JestChaiExpect = JestChaiExpect;
1946
+ exports.JestExtend = JestExtend;
1947
+ exports.MATCHERS_OBJECT = MATCHERS_OBJECT;
1948
+ exports.ObjectContaining = ObjectContaining;
1949
+ exports.StringContaining = StringContaining;
1950
+ exports.StringMatching = StringMatching;
1951
+ exports.addCustomEqualityTesters = addCustomEqualityTesters;
1952
+ exports.arrayBufferEquality = arrayBufferEquality;
1953
+ exports.equals = equals;
1954
+ exports.generateToBeMessage = generateToBeMessage;
1955
+ exports.getObjectKeys = getObjectKeys;
1956
+ exports.getObjectSubset = getObjectSubset;
1957
+ exports.getState = getState;
1958
+ exports.isA = isA;
1959
+ exports.isAsymmetric = isAsymmetric;
1960
+ exports.isImmutableUnorderedKeyed = isImmutableUnorderedKeyed;
1961
+ exports.isImmutableUnorderedSet = isImmutableUnorderedSet;
1962
+ exports.iterableEquality = iterableEquality;
1963
+ exports.pluralize = pluralize;
1964
+ exports.setState = setState;
1965
+ exports.sparseArrayEquality = sparseArrayEquality;
1966
+ exports.subsetEquality = subsetEquality;
1967
+ exports.typeEquality = typeEquality;