@@ -8,6 +8,50 @@ import { useZorm } from "../src";
88import { assertNotAny } from "./test-helpers" ;
99import { createCustomIssues } from "../src/chains" ;
1010
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+
1155test ( "single field validation" , ( ) => {
1256 const Schema = z . object ( {
1357 thing : z . string ( ) . min ( 1 ) ,
0 commit comments