@nestia/e2e 7.0.1 → 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/TestValidator.d.ts +71 -1
- package/lib/TestValidator.js +87 -4
- package/lib/TestValidator.js.map +1 -1
- package/lib/internal/json_equal_to.d.ts +1 -1
- package/lib/internal/json_equal_to.js.map +1 -1
- package/package.json +1 -1
- package/src/TestValidator.ts +88 -4
- package/src/internal/json_equal_to.ts +1 -1
package/lib/TestValidator.d.ts
CHANGED
|
@@ -59,6 +59,21 @@ export declare namespace TestValidator {
|
|
|
59
59
|
* exception filter to ignore specific keys during comparison. Useful for
|
|
60
60
|
* validating API responses, data transformations, and object state changes.
|
|
61
61
|
*
|
|
62
|
+
* **Type Safety Notes:**
|
|
63
|
+
*
|
|
64
|
+
* - The generic type T is inferred from the `actual` parameter (first in the
|
|
65
|
+
* currying chain)
|
|
66
|
+
* - The `expected` parameter must be assignable to `T | null | undefined`
|
|
67
|
+
* - For objects, `expected` must have the same or subset of properties as
|
|
68
|
+
* `actual`
|
|
69
|
+
* - For union types like `string | null`, ensure proper type compatibility:
|
|
70
|
+
*
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const x: string | null;
|
|
73
|
+
* TestValidator.equals("works")(x)(null); // ✅ Works: null is assignable to string | null
|
|
74
|
+
* TestValidator.equals("error")(null)(x); // ❌ Error: x might be string, but expected is null
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
62
77
|
* @example
|
|
63
78
|
* ```typescript
|
|
64
79
|
* // Basic equality
|
|
@@ -72,6 +87,10 @@ export declare namespace TestValidator {
|
|
|
72
87
|
* // Validate API response structure
|
|
73
88
|
* const validateResponse = TestValidator.equals("API response structure");
|
|
74
89
|
* validateResponse({ id: 1, name: "John" })({ id: 1, name: "John" });
|
|
90
|
+
*
|
|
91
|
+
* // Type-safe nullable comparisons
|
|
92
|
+
* const nullableData: { name: string } | null = getData();
|
|
93
|
+
* TestValidator.equals("nullable check")(nullableData)(null); // ✅ Safe
|
|
75
94
|
* ```;
|
|
76
95
|
*
|
|
77
96
|
* @param title - Descriptive title used in error messages when values differ
|
|
@@ -81,7 +100,58 @@ export declare namespace TestValidator {
|
|
|
81
100
|
* actual value
|
|
82
101
|
* @throws Error with detailed diff information when values are not equal
|
|
83
102
|
*/
|
|
84
|
-
const equals: (title: string, exception?: (key: string) => boolean) => <T>(
|
|
103
|
+
const equals: (title: string, exception?: (key: string) => boolean) => <T>(actual: T) => (expected: T | null | undefined) => void;
|
|
104
|
+
/**
|
|
105
|
+
* Validates deep inequality between two values using JSON comparison.
|
|
106
|
+
*
|
|
107
|
+
* Performs recursive comparison of objects and arrays to ensure they are NOT
|
|
108
|
+
* equal. Supports an optional exception filter to ignore specific keys during
|
|
109
|
+
* comparison. Useful for validating that data has changed, objects are
|
|
110
|
+
* different, or mutations have occurred.
|
|
111
|
+
*
|
|
112
|
+
* **Type Safety Notes:**
|
|
113
|
+
*
|
|
114
|
+
* - The generic type T is inferred from the `actual` parameter (first in the
|
|
115
|
+
* currying chain)
|
|
116
|
+
* - The `expected` parameter must be assignable to `T | null | undefined`
|
|
117
|
+
* - For objects, `expected` must have the same or subset of properties as
|
|
118
|
+
* `actual`
|
|
119
|
+
* - For union types like `string | null`, ensure proper type compatibility:
|
|
120
|
+
*
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const x: string | null;
|
|
123
|
+
* TestValidator.notEquals("works")(x)(null); // ✅ Works: null is assignable to string | null
|
|
124
|
+
* TestValidator.notEquals("error")(null)(x); // ❌ Error: x might be string, but expected is null
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Basic inequality
|
|
130
|
+
* TestValidator.notEquals("user should be different after update")(originalUser)(updatedUser);
|
|
131
|
+
*
|
|
132
|
+
* // Ignore timestamps in comparison
|
|
133
|
+
* TestValidator.notEquals("user data should differ", (key) => key === "updatedAt")(
|
|
134
|
+
* originalUser
|
|
135
|
+
* )(modifiedUser);
|
|
136
|
+
*
|
|
137
|
+
* // Validate state changes
|
|
138
|
+
* const validateStateChange = TestValidator.notEquals("state should have changed");
|
|
139
|
+
* validateStateChange(initialState)(currentState);
|
|
140
|
+
*
|
|
141
|
+
* // Type-safe nullable comparisons
|
|
142
|
+
* const mutableData: { count: number } | null = getMutableData();
|
|
143
|
+
* TestValidator.notEquals("should have changed")(mutableData)(null); // ✅ Safe
|
|
144
|
+
* ```;
|
|
145
|
+
*
|
|
146
|
+
* @param title - Descriptive title used in error messages when values are
|
|
147
|
+
* equal
|
|
148
|
+
* @param exception - Optional filter function to exclude specific keys from
|
|
149
|
+
* comparison
|
|
150
|
+
* @returns A currying function chain: first accepts expected value, then
|
|
151
|
+
* actual value
|
|
152
|
+
* @throws Error when values are equal (indicating validation failure)
|
|
153
|
+
*/
|
|
154
|
+
const notEquals: (title: string, exception?: (key: string) => boolean) => <T>(actual: T) => (expected: T | null | undefined) => void;
|
|
85
155
|
/**
|
|
86
156
|
* Validates that a function throws an error or rejects when executed.
|
|
87
157
|
*
|
package/lib/TestValidator.js
CHANGED
|
@@ -168,6 +168,21 @@ var TestValidator;
|
|
|
168
168
|
* exception filter to ignore specific keys during comparison. Useful for
|
|
169
169
|
* validating API responses, data transformations, and object state changes.
|
|
170
170
|
*
|
|
171
|
+
* **Type Safety Notes:**
|
|
172
|
+
*
|
|
173
|
+
* - The generic type T is inferred from the `actual` parameter (first in the
|
|
174
|
+
* currying chain)
|
|
175
|
+
* - The `expected` parameter must be assignable to `T | null | undefined`
|
|
176
|
+
* - For objects, `expected` must have the same or subset of properties as
|
|
177
|
+
* `actual`
|
|
178
|
+
* - For union types like `string | null`, ensure proper type compatibility:
|
|
179
|
+
*
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const x: string | null;
|
|
182
|
+
* TestValidator.equals("works")(x)(null); // ✅ Works: null is assignable to string | null
|
|
183
|
+
* TestValidator.equals("error")(null)(x); // ❌ Error: x might be string, but expected is null
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
171
186
|
* @example
|
|
172
187
|
* ```typescript
|
|
173
188
|
* // Basic equality
|
|
@@ -181,6 +196,10 @@ var TestValidator;
|
|
|
181
196
|
* // Validate API response structure
|
|
182
197
|
* const validateResponse = TestValidator.equals("API response structure");
|
|
183
198
|
* validateResponse({ id: 1, name: "John" })({ id: 1, name: "John" });
|
|
199
|
+
*
|
|
200
|
+
* // Type-safe nullable comparisons
|
|
201
|
+
* const nullableData: { name: string } | null = getData();
|
|
202
|
+
* TestValidator.equals("nullable check")(nullableData)(null); // ✅ Safe
|
|
184
203
|
* ```;
|
|
185
204
|
*
|
|
186
205
|
* @param title - Descriptive title used in error messages when values differ
|
|
@@ -192,14 +211,78 @@ var TestValidator;
|
|
|
192
211
|
*/
|
|
193
212
|
TestValidator.equals = function (title, exception) {
|
|
194
213
|
if (exception === void 0) { exception = function () { return false; }; }
|
|
195
|
-
return function (
|
|
196
|
-
return function (
|
|
197
|
-
var diff = (0, json_equal_to_1.json_equal_to)(exception)(
|
|
214
|
+
return function (actual) {
|
|
215
|
+
return function (expected) {
|
|
216
|
+
var diff = (0, json_equal_to_1.json_equal_to)(exception)(actual)(expected);
|
|
198
217
|
if (diff.length)
|
|
199
218
|
throw new Error([
|
|
200
219
|
"Bug on ".concat(title, ": found different values - [").concat(diff.join(", "), "]:"),
|
|
201
220
|
"\n",
|
|
202
|
-
JSON.stringify({
|
|
221
|
+
JSON.stringify({ actual: actual, expected: expected }, null, 2),
|
|
222
|
+
].join("\n"));
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Validates deep inequality between two values using JSON comparison.
|
|
228
|
+
*
|
|
229
|
+
* Performs recursive comparison of objects and arrays to ensure they are NOT
|
|
230
|
+
* equal. Supports an optional exception filter to ignore specific keys during
|
|
231
|
+
* comparison. Useful for validating that data has changed, objects are
|
|
232
|
+
* different, or mutations have occurred.
|
|
233
|
+
*
|
|
234
|
+
* **Type Safety Notes:**
|
|
235
|
+
*
|
|
236
|
+
* - The generic type T is inferred from the `actual` parameter (first in the
|
|
237
|
+
* currying chain)
|
|
238
|
+
* - The `expected` parameter must be assignable to `T | null | undefined`
|
|
239
|
+
* - For objects, `expected` must have the same or subset of properties as
|
|
240
|
+
* `actual`
|
|
241
|
+
* - For union types like `string | null`, ensure proper type compatibility:
|
|
242
|
+
*
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const x: string | null;
|
|
245
|
+
* TestValidator.notEquals("works")(x)(null); // ✅ Works: null is assignable to string | null
|
|
246
|
+
* TestValidator.notEquals("error")(null)(x); // ❌ Error: x might be string, but expected is null
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* // Basic inequality
|
|
252
|
+
* TestValidator.notEquals("user should be different after update")(originalUser)(updatedUser);
|
|
253
|
+
*
|
|
254
|
+
* // Ignore timestamps in comparison
|
|
255
|
+
* TestValidator.notEquals("user data should differ", (key) => key === "updatedAt")(
|
|
256
|
+
* originalUser
|
|
257
|
+
* )(modifiedUser);
|
|
258
|
+
*
|
|
259
|
+
* // Validate state changes
|
|
260
|
+
* const validateStateChange = TestValidator.notEquals("state should have changed");
|
|
261
|
+
* validateStateChange(initialState)(currentState);
|
|
262
|
+
*
|
|
263
|
+
* // Type-safe nullable comparisons
|
|
264
|
+
* const mutableData: { count: number } | null = getMutableData();
|
|
265
|
+
* TestValidator.notEquals("should have changed")(mutableData)(null); // ✅ Safe
|
|
266
|
+
* ```;
|
|
267
|
+
*
|
|
268
|
+
* @param title - Descriptive title used in error messages when values are
|
|
269
|
+
* equal
|
|
270
|
+
* @param exception - Optional filter function to exclude specific keys from
|
|
271
|
+
* comparison
|
|
272
|
+
* @returns A currying function chain: first accepts expected value, then
|
|
273
|
+
* actual value
|
|
274
|
+
* @throws Error when values are equal (indicating validation failure)
|
|
275
|
+
*/
|
|
276
|
+
TestValidator.notEquals = function (title, exception) {
|
|
277
|
+
if (exception === void 0) { exception = function () { return false; }; }
|
|
278
|
+
return function (actual) {
|
|
279
|
+
return function (expected) {
|
|
280
|
+
var diff = (0, json_equal_to_1.json_equal_to)(exception)(actual)(expected);
|
|
281
|
+
if (diff.length === 0)
|
|
282
|
+
throw new Error([
|
|
283
|
+
"Bug on ".concat(title, ": values should be different but are equal:"),
|
|
284
|
+
"\n",
|
|
285
|
+
JSON.stringify({ actual: actual, expected: expected }, null, 2),
|
|
203
286
|
].join("\n"));
|
|
204
287
|
};
|
|
205
288
|
};
|
package/lib/TestValidator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAoD;AACpD,0DAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,IAAiB,aAAa,
|
|
1
|
+
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAoD;AACpD,0DAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,IAAiB,aAAa,CAinB7B;AAjnBD,WAAiB,aAAa;;IAC5B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,uBAAS,GACpB,UAAC,KAAa;QACd,OAAA,UACE,SAAY;YAEZ,IAAM,OAAO,GAAG;gBACd,OAAA,iBAAU,KAAK,2CAAwC;YAAvD,CAAuD,CAAC;YAE1D,SAAS;YACT,IAAI,OAAO,SAAS,KAAK,SAAS,EAAE,CAAC;gBACnC,IAAI,SAAS,KAAK,IAAI;oBAAE,M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AU;IAC5B,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAa,CAAC,IAAI,KAAK,UAAU;QACzC,OAAQ,KAAa,CAAC,KAAK,KAAK,UAAU,CAC3C,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAI,IAAS,EAAE,IAA4B;IAC3D,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QAC1C,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;IACnD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const json_equal_to: (exception: (key: string) => boolean) => <T>(x: T) => (y: T) => string[];
|
|
1
|
+
export declare const json_equal_to: (exception: (key: string) => boolean) => <T>(x: T) => (y: T | null | undefined) => string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json_equal_to.js","sourceRoot":"","sources":["../../src/internal/json_equal_to.ts"],"names":[],"mappings":";;;AAAO,IAAM,aAAa,GACxB,UAAC,SAAmC;IACpC,OAAA,UAAI,CAAI;QACR,OAAA,UAAC,
|
|
1
|
+
{"version":3,"file":"json_equal_to.js","sourceRoot":"","sources":["../../src/internal/json_equal_to.ts"],"names":[],"mappings":";;;AAAO,IAAM,aAAa,GACxB,UAAC,SAAmC;IACpC,OAAA,UAAI,CAAI;QACR,OAAA,UAAC,CAAuB;YACtB,IAAM,SAAS,GAAa,EAAE,CAAC;YAC/B,IAAM,OAAO,GACX,UAAC,QAAgB;gBACjB,OAAA,UAAC,CAAM;oBACP,OAAA,UAAC,CAAM;wBACL,IAAI,OAAO,CAAC,KAAK,UAAU,IAAI,OAAO,CAAC,KAAK,UAAU;4BAAE,OAAO;6BAC1D,IAAI,OAAO,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D,OAAO,CAAC,UAAC,GAAG,IAAK,OAAA,OAAO,CAAC,UAAG,QAAQ,cAAI,GAAG,CAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAA7C,CAA6C,CAAC;oBAFlE,CAEkE;gBAHpE,CAGoE;YAJpE,CAIoE,CAAC;YAEvE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAClB,OAAO,SAAS,CAAC;QACnB,CAAC;IA/BD,CA+BC;AAhCD,CAgCC,CAAC;AAlCS,QAAA,aAAa,iBAkCtB"}
|
package/package.json
CHANGED
package/src/TestValidator.ts
CHANGED
|
@@ -93,6 +93,21 @@ export namespace TestValidator {
|
|
|
93
93
|
* exception filter to ignore specific keys during comparison. Useful for
|
|
94
94
|
* validating API responses, data transformations, and object state changes.
|
|
95
95
|
*
|
|
96
|
+
* **Type Safety Notes:**
|
|
97
|
+
*
|
|
98
|
+
* - The generic type T is inferred from the `actual` parameter (first in the
|
|
99
|
+
* currying chain)
|
|
100
|
+
* - The `expected` parameter must be assignable to `T | null | undefined`
|
|
101
|
+
* - For objects, `expected` must have the same or subset of properties as
|
|
102
|
+
* `actual`
|
|
103
|
+
* - For union types like `string | null`, ensure proper type compatibility:
|
|
104
|
+
*
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const x: string | null;
|
|
107
|
+
* TestValidator.equals("works")(x)(null); // ✅ Works: null is assignable to string | null
|
|
108
|
+
* TestValidator.equals("error")(null)(x); // ❌ Error: x might be string, but expected is null
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
96
111
|
* @example
|
|
97
112
|
* ```typescript
|
|
98
113
|
* // Basic equality
|
|
@@ -106,6 +121,10 @@ export namespace TestValidator {
|
|
|
106
121
|
* // Validate API response structure
|
|
107
122
|
* const validateResponse = TestValidator.equals("API response structure");
|
|
108
123
|
* validateResponse({ id: 1, name: "John" })({ id: 1, name: "John" });
|
|
124
|
+
*
|
|
125
|
+
* // Type-safe nullable comparisons
|
|
126
|
+
* const nullableData: { name: string } | null = getData();
|
|
127
|
+
* TestValidator.equals("nullable check")(nullableData)(null); // ✅ Safe
|
|
109
128
|
* ```;
|
|
110
129
|
*
|
|
111
130
|
* @param title - Descriptive title used in error messages when values differ
|
|
@@ -117,15 +136,80 @@ export namespace TestValidator {
|
|
|
117
136
|
*/
|
|
118
137
|
export const equals =
|
|
119
138
|
(title: string, exception: (key: string) => boolean = () => false) =>
|
|
120
|
-
<T>(
|
|
121
|
-
(
|
|
122
|
-
const diff: string[] = json_equal_to(exception)(
|
|
139
|
+
<T>(actual: T) =>
|
|
140
|
+
(expected: T | null | undefined) => {
|
|
141
|
+
const diff: string[] = json_equal_to(exception)(actual)(expected);
|
|
123
142
|
if (diff.length)
|
|
124
143
|
throw new Error(
|
|
125
144
|
[
|
|
126
145
|
`Bug on ${title}: found different values - [${diff.join(", ")}]:`,
|
|
127
146
|
"\n",
|
|
128
|
-
JSON.stringify({
|
|
147
|
+
JSON.stringify({ actual, expected }, null, 2),
|
|
148
|
+
].join("\n"),
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Validates deep inequality between two values using JSON comparison.
|
|
154
|
+
*
|
|
155
|
+
* Performs recursive comparison of objects and arrays to ensure they are NOT
|
|
156
|
+
* equal. Supports an optional exception filter to ignore specific keys during
|
|
157
|
+
* comparison. Useful for validating that data has changed, objects are
|
|
158
|
+
* different, or mutations have occurred.
|
|
159
|
+
*
|
|
160
|
+
* **Type Safety Notes:**
|
|
161
|
+
*
|
|
162
|
+
* - The generic type T is inferred from the `actual` parameter (first in the
|
|
163
|
+
* currying chain)
|
|
164
|
+
* - The `expected` parameter must be assignable to `T | null | undefined`
|
|
165
|
+
* - For objects, `expected` must have the same or subset of properties as
|
|
166
|
+
* `actual`
|
|
167
|
+
* - For union types like `string | null`, ensure proper type compatibility:
|
|
168
|
+
*
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const x: string | null;
|
|
171
|
+
* TestValidator.notEquals("works")(x)(null); // ✅ Works: null is assignable to string | null
|
|
172
|
+
* TestValidator.notEquals("error")(null)(x); // ❌ Error: x might be string, but expected is null
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // Basic inequality
|
|
178
|
+
* TestValidator.notEquals("user should be different after update")(originalUser)(updatedUser);
|
|
179
|
+
*
|
|
180
|
+
* // Ignore timestamps in comparison
|
|
181
|
+
* TestValidator.notEquals("user data should differ", (key) => key === "updatedAt")(
|
|
182
|
+
* originalUser
|
|
183
|
+
* )(modifiedUser);
|
|
184
|
+
*
|
|
185
|
+
* // Validate state changes
|
|
186
|
+
* const validateStateChange = TestValidator.notEquals("state should have changed");
|
|
187
|
+
* validateStateChange(initialState)(currentState);
|
|
188
|
+
*
|
|
189
|
+
* // Type-safe nullable comparisons
|
|
190
|
+
* const mutableData: { count: number } | null = getMutableData();
|
|
191
|
+
* TestValidator.notEquals("should have changed")(mutableData)(null); // ✅ Safe
|
|
192
|
+
* ```;
|
|
193
|
+
*
|
|
194
|
+
* @param title - Descriptive title used in error messages when values are
|
|
195
|
+
* equal
|
|
196
|
+
* @param exception - Optional filter function to exclude specific keys from
|
|
197
|
+
* comparison
|
|
198
|
+
* @returns A currying function chain: first accepts expected value, then
|
|
199
|
+
* actual value
|
|
200
|
+
* @throws Error when values are equal (indicating validation failure)
|
|
201
|
+
*/
|
|
202
|
+
export const notEquals =
|
|
203
|
+
(title: string, exception: (key: string) => boolean = () => false) =>
|
|
204
|
+
<T>(actual: T) =>
|
|
205
|
+
(expected: T | null | undefined) => {
|
|
206
|
+
const diff: string[] = json_equal_to(exception)(actual)(expected);
|
|
207
|
+
if (diff.length === 0)
|
|
208
|
+
throw new Error(
|
|
209
|
+
[
|
|
210
|
+
`Bug on ${title}: values should be different but are equal:`,
|
|
211
|
+
"\n",
|
|
212
|
+
JSON.stringify({ actual, expected }, null, 2),
|
|
129
213
|
].join("\n"),
|
|
130
214
|
);
|
|
131
215
|
};
|