Skip to content

fix: let returns override returnsArg#2724

Merged
mroderick merged 1 commit into
sinonjs:mainfrom
pupuking723:fix/returns-overrides-returnsarg
Jul 20, 2026
Merged

fix: let returns override returnsArg#2724
mroderick merged 1 commit into
sinonjs:mainfrom
pupuking723:fix/returns-overrides-returnsarg

Conversation

@pupuking723

Copy link
Copy Markdown
Contributor

Fixes #2656.

This clears the previous returnsArg() behavior when returns() is configured afterwards. Without clearing returnArgAt, the behavior invocation path still prioritizes returnsArg over the explicit return value, so stub.returnsArg(0).returns(42) returns the first argument instead of 42.

The added regression test covers that chaining order directly.

Verification:

  • npm run test-node -- test/src/stub-test.js --grep "is superseded by returns"
  • npm run test-node -- test/src/stub-test.js --grep "returnsArg"
  • npm run test-node -- test/src/stub-test.js
  • npm run test-node
  • npx eslint src/sinon/default-behaviors.js test/src/stub-test.js --max-warnings 0
  • npx prettier --check src/sinon/default-behaviors.js test/src/stub-test.js

Signed-off-by: 王胜 <2318857637@qq.com>
@hexeberlin hexeberlin added the semver:patch changes will cause a new patch version label Jul 20, 2026
@mroderick

Copy link
Copy Markdown
Member

Closing and re-opening to diagnose issues with GitHub Actions

@mroderick mroderick closed this Jul 20, 2026
@mroderick mroderick reopened this Jul 20, 2026
@mroderick

Copy link
Copy Markdown
Member

That worked!

@mroderick
mroderick merged commit d36e921 into sinonjs:main Jul 20, 2026
15 checks passed
@mroderick

Copy link
Copy Markdown
Member

Thank you for your contribution to Sinon @pupuking723 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:patch changes will cause a new patch version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

returns() doesn't override returnsArg()

3 participants