Skip to content

Commit 63b2af1

Browse files
committed
fix form tests
1 parent 49deca3 commit 63b2af1

File tree

1 file changed

+55
-45
lines changed

1 file changed

+55
-45
lines changed

packages/kit/test/types/remote.test.ts

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ function form_tests() {
170170
return { success: true };
171171
});
172172

173-
f.result?.success === true;
173+
const fi = f();
174174

175-
f.enhance(async ({ submit }) => {
175+
fi.result?.success === true;
176+
177+
fi.enhance(async ({ submit }) => {
176178
const x: void = await submit();
177179
x;
178180
const y: void = await submit().updates(
@@ -202,18 +204,19 @@ function form_tests() {
202204
return { success: true };
203205
}
204206
);
207+
const f2i = f2();
205208
// @ts-expect-error
206-
f2.fields.name();
207-
f2.fields.a.issues();
208-
f2.fields.nested.prop.issues();
209+
f2i.fields.name();
210+
f2i.fields.a.issues();
211+
f2i.fields.nested.prop.issues();
209212
// @ts-expect-error
210-
f2.fields.nonexistent.issues();
211-
f2.fields.a.value();
212-
f2.fields.nested.prop.value();
213+
f2i.fields.nonexistent.issues();
214+
f2i.fields.a.value();
215+
f2i.fields.nested.prop.value();
213216
// @ts-expect-error
214-
f2.fields.nonexistent.value();
217+
f2i.fields.nonexistent.value();
215218
// @ts-expect-error
216-
f2.fields.array[0].array.name();
219+
f2i.fields.array[0].array.name();
217220

218221
// all schema properties optional
219222
const f3 = form(
@@ -238,27 +241,29 @@ function form_tests() {
238241
return { success: true };
239242
}
240243
);
244+
const f3i = f3();
241245
// @ts-expect-error
242-
f3.fields.name();
243-
f3.fields.a.issues();
244-
f3.fields.a.value();
245-
f3.fields.nested.prop.issues();
246-
f3.fields.nested.prop.value();
246+
f3i.fields.name();
247+
f3i.fields.a.issues();
248+
f3i.fields.a.value();
249+
f3i.fields.nested.prop.issues();
250+
f3i.fields.nested.prop.value();
247251
// @ts-expect-error
248-
f3.fields.nonexistent.name();
252+
f3i.fields.nonexistent.name();
249253

250254
// index signature schema
251255
const f4 = form(null as any as StandardSchemaV1<Record<string, any>>, (data) => {
252256
data.a === '';
253257
data.nested?.prop === '';
254258
return { success: true };
255259
});
260+
const f4i = f4();
256261
// @ts-expect-error
257-
f4.fields.name();
258-
f4.fields.a.issues();
259-
f4.fields.a.value();
260-
f4.fields.nested.prop.issues();
261-
f4.fields.nested.prop.value();
262+
f4i.fields.name();
263+
f4i.fields.a.issues();
264+
f4i.fields.a.value();
265+
f4i.fields.nested.prop.issues();
266+
f4i.fields.nested.prop.value();
262267

263268
// schema with union types
264269
const f5 = form(
@@ -277,16 +282,17 @@ function form_tests() {
277282
return { success: true };
278283
}
279284
);
285+
const f5i = f5();
280286
// @ts-expect-error
281-
f5.fields.name();
282-
f5.fields.foo.issues();
283-
f5.fields.bar.issues();
284-
f5.fields.foo.value();
285-
f5.fields.bar.value() === 'c';
287+
f5i.fields.name();
288+
f5i.fields.foo.issues();
289+
f5i.fields.bar.issues();
290+
f5i.fields.foo.value();
291+
f5i.fields.bar.value() === 'c';
286292
// @ts-expect-error
287-
f5.fields.foo.value() === 'e';
293+
f5i.fields.foo.value() === 'e';
288294
// @ts-expect-error
289-
f5.fields.nonexistent.name();
295+
f5i.fields.nonexistent.name();
290296

291297
// schema with arrays
292298
const f6 = form(
@@ -305,19 +311,20 @@ function form_tests() {
305311
return { success: true };
306312
}
307313
);
314+
const f6i = f6();
308315
// @ts-expect-error
309-
f6.fields.name();
316+
f6i.fields.name();
310317
// @ts-expect-error
311-
f6.field('array[0].array');
312-
f6.fields.array.issues();
313-
f6.fields.array[0].prop.issues();
314-
f6.fields.array[0].array.issues();
318+
f6i.field('array[0].array');
319+
f6i.fields.array.issues();
320+
f6i.fields.array[0].prop.issues();
321+
f6i.fields.array[0].array.issues();
315322
// @ts-expect-error
316-
f6.fields.nonexistent.issues();
317-
f6.fields.array[0].prop.value();
318-
f6.fields.array[0].array.value();
323+
f6i.fields.nonexistent.issues();
324+
f6i.fields.array[0].prop.value();
325+
f6i.fields.array[0].array.value();
319326
// @ts-expect-error
320-
f6.fields.array[0].array.name();
327+
f6i.fields.array[0].array.name();
321328

322329
// any
323330
const f7 = form(null as any, (data, invalid) => {
@@ -326,12 +333,13 @@ function form_tests() {
326333
invalid('foo', invalid.nested.prop('bar'));
327334
return { success: true };
328335
});
336+
const f7i = f7();
329337
// @ts-expect-error
330-
f7.fields.name();
331-
f7.fields.a.issues();
332-
f7.fields.a.value();
333-
f7.fields.nested.prop.issues();
334-
f7.fields.nested.prop.value();
338+
f7i.fields.name();
339+
f7i.fields.a.issues();
340+
f7i.fields.a.value();
341+
f7i.fields.nested.prop.issues();
342+
f7i.fields.nested.prop.value();
335343

336344
// no schema
337345
const f8 = form((invalid) => {
@@ -341,14 +349,16 @@ function form_tests() {
341349
invalid.x('bar')
342350
);
343351
});
352+
const f8i = f8();
344353
// @ts-expect-error
345-
f8.fields.x;
354+
f8i.fields.x;
346355
// @ts-expect-error
347-
f6.input!['array[0].prop'] = 123;
356+
f8i.input!['array[0].prop'] = 123;
348357

349358
// doesn't use data
350359
const f9 = form(() => Promise.resolve({ success: true }));
351-
f9.result?.success === true;
360+
const f9i = f9();
361+
f9i.result?.success === true;
352362
}
353363
form_tests();
354364

0 commit comments

Comments
 (0)