@@ -15,6 +15,27 @@ describe("valid input", () => {
1515 age : "20" ,
1616 } ) ;
1717 } ) ;
18+
19+ it ( "returns empty data and no issues for empty FormData" , ( ) => {
20+ const fd = new FormData ( ) ;
21+
22+ const result = parse ( fd ) ;
23+
24+ expect ( result . issues ) . toEqual ( [ ] ) ;
25+ expect ( result . data ) . toEqual ( { } ) ;
26+ } ) ;
27+
28+ it ( "stores File values in data" , ( ) => {
29+ const fd = new FormData ( ) ;
30+ const file = new File ( [ "content" ] , "test.txt" , { type : "text/plain" } ) ;
31+ fd . append ( "upload" , file ) ;
32+
33+ const result = parse ( fd ) ;
34+
35+ assert ( result . data !== null ) ;
36+ expect ( result . issues ) . toEqual ( [ ] ) ;
37+ expect ( result . data [ "upload" ] ) . toBeInstanceOf ( File ) ;
38+ } ) ;
1839} ) ;
1940
2041describe ( "duplicate key detection" , ( ) => {
@@ -34,6 +55,22 @@ describe("duplicate key detection", () => {
3455 expect ( issue . key ) . toBe ( "a" ) ;
3556 } ) ;
3657
58+ it ( "reports an issue for each occurrence beyond the first" , ( ) => {
59+ const fd = new FormData ( ) ;
60+ fd . append ( "a" , "1" ) ;
61+ fd . append ( "a" , "2" ) ;
62+ fd . append ( "a" , "3" ) ;
63+
64+ const result = parse ( fd ) ;
65+
66+ expect ( result . data ) . toBeNull ( ) ;
67+ expect ( result . issues ) . toHaveLength ( 2 ) ;
68+ for ( const issue of result . issues ) {
69+ expect ( issue . code ) . toBe ( "duplicate_key" ) ;
70+ expect ( issue . key ) . toBe ( "a" ) ;
71+ }
72+ } ) ;
73+
3774 it ( "treats bracket notation as opaque keys" , ( ) => {
3875 const fd = new FormData ( ) ;
3976 fd . append ( "items[]" , "1" ) ;
0 commit comments