File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed
Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -113,10 +113,12 @@ export function useForm({
113113 reset ( ) ;
114114 }
115115 await onSuccess ( ) ;
116+ } catch ( error ) {
117+ await onFailure ( error ) ;
118+ throw error ;
116119 } finally {
117120 setLoading ( false ) ;
118121 setDisabled ( false ) ;
119- await onFailure ( ) ;
120122 }
121123 }
122124
Original file line number Diff line number Diff line change @@ -183,9 +183,7 @@ describe('useForm', () => {
183183 expect ( onSuccess ) . toHaveBeenCalled ( ) ;
184184 } ) ;
185185
186- it ( 'always calls onFailure in finally block (current behavior)' , async ( ) => {
187- // NOTE: This documents current behavior where onFailure is called even on success
188- // This may be a bug or intentional cleanup callback - kept for regression safety
186+ it ( 'does not call onFailure on successful submit' , async ( ) => {
189187 const onSuccess = jest . fn ( ) ;
190188 const onFailure = jest . fn ( ) ;
191189 const submitter = jest . fn ( ) . mockResolvedValue ( undefined ) ;
@@ -202,7 +200,7 @@ describe('useForm', () => {
202200 } ) ;
203201
204202 expect ( onSuccess ) . toHaveBeenCalled ( ) ;
205- expect ( onFailure ) . toHaveBeenCalled ( ) ; // Called even on success
203+ expect ( onFailure ) . not . toHaveBeenCalled ( ) ;
206204 } ) ;
207205
208206 it ( 'clears form when clearOnSuccess is true' , async ( ) => {
You can’t perform that action at this time.
0 commit comments