Skip to content

fix: honour callThrough() set on a specific call - #2766

Open
dylanpulver wants to merge 1 commit into
sinonjs:mainfrom
dylanpulver:fix/oncall-callthrough-is-present
Open

dylanpulver wants to merge 1 commit into
sinonjs:mainfrom
dylanpulver:fix/oncall-callthrough-is-present

Conversation

@dylanpulver

Copy link
Copy Markdown

Purpose (TL;DR) - mandatory

behavior.isPresent() decides whether a per-call behaviour from onCall()/onFirstCall() is used at all. It lists the flags invoke() dispatches on — but callsThrough and callsThroughWithNew were never added, so stub.onFirstCall().callThrough() is a silent no-op: the default behaviour runs and the original method is never called.

invoke() dispatches on 14 flags; isPresent() gated 12. The two missing ones are exactly these. callThrough() also sets returnValueDefined = false, so nothing else in the list can compensate.

Same shape as #1526, which was fixed for exceptionCreator in 7b53434 by adding the missing flag to this same list.

How to verify - mandatory

  1. Check out this branch
  2. npm install
  3. npx mocha --recursive "test/{src,issues,scripts}/**/*-test.js"

Same command, same tree, three variants:

source passing failing
main + the new tests only 1556 2
main + only callsThrough added 1557 1
this PR 1558 0

Row 1 shows the tests fail without the fix; row 2 is why both flags are needed.

npm run lint, npm run prettier:check and npm run test-contract are green, and the public API manifest is unchanged. I ran the Node suite locally; CI covers browser/webworker.

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached (none added)

Written with AI assistance (Claude Opus 5, claude-opus-5).

behavior.isPresent() decides whether a per-call behaviour created by
onCall()/onFirstCall() is used at all. It lists the flags that invoke()
dispatches on, but callsThrough and callsThroughWithNew were never added
to it, so a per-call .callThrough() reported "no behaviour here" and
getCurrentBehavior fell back to the default behaviour. The original
method was silently never called, with no error or warning.

callThrough() also sets returnValueDefined to false, so nothing else in
the list could compensate.

This is the same regression shape as sinonjs#1526, which was fixed for
exceptionCreator in 7b53434 by adding the missing flag to the same list.

Co-authored-by: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant