File tree 1 file changed +43
-0
lines changed
packages/react-zorm/__tests__
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,49 @@ 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
+ entry [ 1 ] = realFile ;
35
+ }
36
+ }
37
+ }
38
+
39
+ yield entry ;
40
+ }
41
+ }
42
+ }
43
+
44
+ const OrigFormData = globalThis . FormData ;
45
+
46
+ beforeAll ( ( ) => {
47
+ globalThis . FormData = WorkaroundFormData ;
48
+ } ) ;
49
+
50
+ afterAll ( ( ) => {
51
+ globalThis . FormData = OrigFormData ;
52
+ } ) ;
53
+
11
54
test ( "single field validation" , ( ) => {
12
55
const Schema = z . object ( {
13
56
thing : z . string ( ) . min ( 1 ) ,
You can’t perform that action at this time.
0 commit comments