@@ -906,11 +906,11 @@ test.skip("[TYPE ONLY] can narrow validation type to success", () => {
906
906
} ) ;
907
907
908
908
test ( "can validate files" , async ( ) => {
909
- const spy = jest . fn ( ) ;
909
+ const refineSpy = jest . fn ( ) ;
910
910
911
911
const Schema = z . object ( {
912
912
myFile : z . instanceof ( File ) . refine ( ( file ) => {
913
- spy ( file . type ) ;
913
+ refineSpy ( file . type ) ;
914
914
return file . type === "image/png" ;
915
915
} , "Only .png images are allowed" ) ,
916
916
} ) ;
@@ -943,28 +943,15 @@ test("can validate files", async () => {
943
943
await userEvent . upload ( fileInput , file ) ;
944
944
fireEvent . submit ( screen . getByTestId ( "form" ) ) ;
945
945
946
- {
947
- // TEMP TESTS
948
- const form = screen . getByTestId ( "form" ) as HTMLFormElement ;
949
- expect ( fileInput . files ?. [ 0 ] ?. name ) . toBe ( "chucknorris.txt" ) ;
950
- const formData = new FormData ( form ) ;
951
- expect ( formData . get ( "myFile" ) ) . toBeInstanceOf ( File ) ;
952
- const formFile = formData . get ( "myFile" ) as File ;
953
-
954
- // XXX Bug in jsdom or react testing lib?
955
- // FormData cannot read file from the form.
956
- expect ( formFile . name ) . toBe ( "chucknorris.txt" ) ;
957
- }
958
-
959
- expect ( spy ) . toHaveBeenCalledWith ( "text/plain" ) ;
946
+ expect ( refineSpy ) . toHaveBeenCalledWith ( "text/plain" ) ;
960
947
961
948
expect ( screen . queryByTestId ( "error" ) ) . toHaveTextContent (
962
949
"Only .png images are allowed" ,
963
950
) ;
964
951
} ) ;
965
952
966
953
test ( "can submit files" , async ( ) => {
967
- const spy = jest . fn ( ) ;
954
+ const submitSpy = jest . fn ( ) ;
968
955
969
956
const Schema = z . object ( {
970
957
myFile : z . instanceof ( File ) . refine ( ( file ) => {
@@ -975,7 +962,7 @@ test("can submit files", async () => {
975
962
function Test ( ) {
976
963
const zo = useZorm ( "form" , Schema , {
977
964
onValidSubmit ( e ) {
978
- spy ( e . data . myFile . name ) ;
965
+ submitSpy ( e . data . myFile . name ) ;
979
966
} ,
980
967
} ) ;
981
968
@@ -1004,5 +991,5 @@ test("can submit files", async () => {
1004
991
await userEvent . upload ( fileInput , file ) ;
1005
992
fireEvent . submit ( screen . getByTestId ( "form" ) ) ;
1006
993
1007
- expect ( spy ) . toHaveBeenCalledWith ( "text/plain " ) ;
994
+ expect ( submitSpy ) . toHaveBeenCalledWith ( "chucknorris.png " ) ;
1008
995
} ) ;
0 commit comments