Skip to content

Fix react-hook-form task 153: handleSubmit 3rd arg type mismatch with test#41

Merged
akhatua2 merged 1 commit intocooperbench:mainfrom
AlienKevin:fix/react-hook-form-t153-onfinally
Mar 21, 2026
Merged

Fix react-hook-form task 153: handleSubmit 3rd arg type mismatch with test#41
akhatua2 merged 1 commit intocooperbench:mainfrom
AlienKevin:fix/react-hook-form-t153-onfinally

Conversation

@AlienKevin
Copy link
Contributor

Summary

  • The combined.patch changes handleSubmit signature to (onValid, onInvalid, options) where options is an object { onFinally?: ..., onBeforeValidate?: ..., ... }
  • The test patch (tests2.patch) passes onFinally as a bare function in the 3rd positional argument: handleSubmit(onValidCallback, onInvalidCallback, onFinallyCallback)
  • Since the implementation checks options?.onFinally, and options is actually a function (not an object), onFinally is never invoked
  • All 3 onFinally tests fail with "Expected 1 calls, received 0 calls"

Fix

Add runtime type detection for the 3rd argument in combined.patch:

const options = typeof optionsOrOnFinally === 'function'
  ? { onFinally: optionsOrOnFinally }
  : optionsOrOnFinally;

This accepts both handleSubmit(valid, invalid, onFinallyFn) and handleSubmit(valid, invalid, { onFinally: fn, ... }). The TypeScript type definition is updated to match.

Test plan

  • Oracle test passes for react-hook-form task 153 (both features)
  • Verified on Modal with Harbor evaluation framework

The combined.patch uses handleSubmit(onValid, onInvalid, options) where
options is an object, but the test patch passes onFinally as a bare
function in the 3rd positional argument. Since the implementation checks
options?.onFinally and options is a function (not an object), onFinally
is never invoked and all 3 onFinally tests fail.

Add runtime type detection to accept both call styles:
  handleSubmit(valid, invalid, onFinallyFn)        -- bare function
  handleSubmit(valid, invalid, { onFinally: fn })   -- options object
@akhatua2 akhatua2 merged commit 6690bd1 into cooperbench:main Mar 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants