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