@@ -8,6 +8,50 @@ import { useZorm } from "../src";
8
8
import { assertNotAny } from "./test-helpers" ;
9
9
import { createCustomIssues } from "../src/chains" ;
10
10
11
+ /**
12
+ * For https://github.com/testing-library/user-event/pull/1109
13
+ */
14
+ class WorkaroundFormData extends FormData {
15
+ #formRef?: HTMLFormElement ;
16
+ constructor ( ...args : ConstructorParameters < typeof FormData > ) {
17
+ super ( ...args ) ;
18
+ this . #formRef = args [ 0 ] ;
19
+ }
20
+
21
+ // React Zorm only uses entries() so this is the only method we need to patch
22
+ override * entries ( ) {
23
+ for ( const [ name , value ] of super . entries ( ) ) {
24
+ const entry : [ string , FormDataEntryValue ] = [ name , value ] ;
25
+
26
+ if ( value instanceof File && this . #formRef) {
27
+ const input = this . #formRef. querySelector (
28
+ `input[name="${ name } "]` ,
29
+ ) ;
30
+
31
+ if ( input instanceof HTMLInputElement ) {
32
+ const realFile = input ?. files ?. [ 0 ] ;
33
+ if ( realFile ) {
34
+ console . log ( "file" , realFile . name ) ;
35
+ entry [ 1 ] = realFile ;
36
+ }
37
+ }
38
+ }
39
+
40
+ yield entry ;
41
+ }
42
+ }
43
+ }
44
+
45
+ const OrigFormData = globalThis . FormData ;
46
+
47
+ beforeAll ( ( ) => {
48
+ globalThis . FormData = WorkaroundFormData ;
49
+ } ) ;
50
+
51
+ afterAll ( ( ) => {
52
+ globalThis . FormData = OrigFormData ;
53
+ } ) ;
54
+
11
55
test ( "single field validation" , ( ) => {
12
56
const Schema = z . object ( {
13
57
thing : z . string ( ) . min ( 1 ) ,
0 commit comments