@nestia/e2e 7.0.2 → 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 +40 -2
- package/lib/TestValidator.js +46 -8
- package/lib/TestValidator.js.map +1 -1
- package/package.json +1 -1
- package/src/TestValidator.ts +46 -8
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,7 @@ 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;
|
|
85
104
|
/**
|
|
86
105
|
* Validates deep inequality between two values using JSON comparison.
|
|
87
106
|
*
|
|
@@ -90,6 +109,21 @@ export declare namespace TestValidator {
|
|
|
90
109
|
* comparison. Useful for validating that data has changed, objects are
|
|
91
110
|
* different, or mutations have occurred.
|
|
92
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
|
+
*
|
|
93
127
|
* @example
|
|
94
128
|
* ```typescript
|
|
95
129
|
* // Basic inequality
|
|
@@ -103,6 +137,10 @@ export declare namespace TestValidator {
|
|
|
103
137
|
* // Validate state changes
|
|
104
138
|
* const validateStateChange = TestValidator.notEquals("state should have changed");
|
|
105
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
|
|
106
144
|
* ```;
|
|
107
145
|
*
|
|
108
146
|
* @param title - Descriptive title used in error messages when values are
|
|
@@ -113,7 +151,7 @@ export declare namespace TestValidator {
|
|
|
113
151
|
* actual value
|
|
114
152
|
* @throws Error when values are equal (indicating validation failure)
|
|
115
153
|
*/
|
|
116
|
-
const notEquals: (title: string, exception?: (key: string) => boolean) => <T>(
|
|
154
|
+
const notEquals: (title: string, exception?: (key: string) => boolean) => <T>(actual: T) => (expected: T | null | undefined) => void;
|
|
117
155
|
/**
|
|
118
156
|
* Validates that a function throws an error or rejects when executed.
|
|
119
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,14 @@ 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),
|
|
203
222
|
].join("\n"));
|
|
204
223
|
};
|
|
205
224
|
};
|
|
@@ -212,6 +231,21 @@ var TestValidator;
|
|
|
212
231
|
* comparison. Useful for validating that data has changed, objects are
|
|
213
232
|
* different, or mutations have occurred.
|
|
214
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
|
+
*
|
|
215
249
|
* @example
|
|
216
250
|
* ```typescript
|
|
217
251
|
* // Basic inequality
|
|
@@ -225,6 +259,10 @@ var TestValidator;
|
|
|
225
259
|
* // Validate state changes
|
|
226
260
|
* const validateStateChange = TestValidator.notEquals("state should have changed");
|
|
227
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
|
|
228
266
|
* ```;
|
|
229
267
|
*
|
|
230
268
|
* @param title - Descriptive title used in error messages when values are
|
|
@@ -237,14 +275,14 @@ var TestValidator;
|
|
|
237
275
|
*/
|
|
238
276
|
TestValidator.notEquals = function (title, exception) {
|
|
239
277
|
if (exception === void 0) { exception = function () { return false; }; }
|
|
240
|
-
return function (
|
|
241
|
-
return function (
|
|
242
|
-
var diff = (0, json_equal_to_1.json_equal_to)(exception)(
|
|
278
|
+
return function (actual) {
|
|
279
|
+
return function (expected) {
|
|
280
|
+
var diff = (0, json_equal_to_1.json_equal_to)(exception)(actual)(expected);
|
|
243
281
|
if (diff.length === 0)
|
|
244
282
|
throw new Error([
|
|
245
283
|
"Bug on ".concat(title, ": values should be different but are equal:"),
|
|
246
284
|
"\n",
|
|
247
|
-
JSON.stringify({
|
|
285
|
+
JSON.stringify({ actual: actual, expected: expected }, null, 2),
|
|
248
286
|
].join("\n"));
|
|
249
287
|
};
|
|
250
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;;;;;;;;;;;;;;;;;;;;;;;;;GA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5D,MAAM,IAAI,KAAK,CACb,iBAAU,KAAK,gCAAsB,SAAS,cAAI,MAAM,CAAC,IAAI,CAC3D,IAAI,CACL,OAAI,CACN,CAAC;wCACJ,CAAC;;;;;qBACF;gBAtBD,CAsBC;YAvBD,CAuBC;QAxBD,CAwBC;IAjCD,CAiCC,CAAC;AAqBN,CAAC,EAjnBgB,aAAa,6BAAb,aAAa,QAinB7B;AAMD,SAAS,OAAO,CAA8B,QAAkB;IAC9D,OAAO,QAAQ,CAAC,GAAG,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,EAAE,EAAT,CAAS,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAhB,CAAgB,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,UAAU,CAAC,KAAU;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"}
|
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,15 @@ 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),
|
|
129
148
|
].join("\n"),
|
|
130
149
|
);
|
|
131
150
|
};
|
|
@@ -138,6 +157,21 @@ export namespace TestValidator {
|
|
|
138
157
|
* comparison. Useful for validating that data has changed, objects are
|
|
139
158
|
* different, or mutations have occurred.
|
|
140
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
|
+
*
|
|
141
175
|
* @example
|
|
142
176
|
* ```typescript
|
|
143
177
|
* // Basic inequality
|
|
@@ -151,6 +185,10 @@ export namespace TestValidator {
|
|
|
151
185
|
* // Validate state changes
|
|
152
186
|
* const validateStateChange = TestValidator.notEquals("state should have changed");
|
|
153
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
|
|
154
192
|
* ```;
|
|
155
193
|
*
|
|
156
194
|
* @param title - Descriptive title used in error messages when values are
|
|
@@ -163,15 +201,15 @@ export namespace TestValidator {
|
|
|
163
201
|
*/
|
|
164
202
|
export const notEquals =
|
|
165
203
|
(title: string, exception: (key: string) => boolean = () => false) =>
|
|
166
|
-
<T>(
|
|
167
|
-
(
|
|
168
|
-
const diff: string[] = json_equal_to(exception)(
|
|
204
|
+
<T>(actual: T) =>
|
|
205
|
+
(expected: T | null | undefined) => {
|
|
206
|
+
const diff: string[] = json_equal_to(exception)(actual)(expected);
|
|
169
207
|
if (diff.length === 0)
|
|
170
208
|
throw new Error(
|
|
171
209
|
[
|
|
172
210
|
`Bug on ${title}: values should be different but are equal:`,
|
|
173
211
|
"\n",
|
|
174
|
-
JSON.stringify({
|
|
212
|
+
JSON.stringify({ actual, expected }, null, 2),
|
|
175
213
|
].join("\n"),
|
|
176
214
|
);
|
|
177
215
|
};
|