Skip to content

Commit 6fdf524

Browse files
Fixing jest tests.
1 parent 8e28adc commit 6fdf524

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

app/src/hooks/useForm.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

app/src/hooks/useForm.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff 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 () => {

0 commit comments

Comments
 (0)