Skip to content

fix: let returns override returnsArg#2724

Open
pupuking723 wants to merge 1 commit into
sinonjs:mainfrom
pupuking723:fix/returns-overrides-returnsarg
Open

fix: let returns override returnsArg#2724
pupuking723 wants to merge 1 commit into
sinonjs:mainfrom
pupuking723:fix/returns-overrides-returnsarg

Conversation

@pupuking723

Copy link
Copy Markdown

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

returns() doesn't override returnsArg()

1 participant