Fix mock onCall behavior for matching expectations#2717
Open
puneetdixit200 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose (TL;DR) - mandatory
Fixes #2663 by making ordered mock expectations use the method-level call index when selecting
onCall()behavior.Background (Problem in detail) - optional
When separate expectations are configured for the same mocked method, each expectation only sees its own call count. That meant
onCall(1)oronCall(2)on later matching expectations fell back to default behavior, socallsFake()returnedundefined.Solution - optional
invokeMethod()now computes the current call index across all expectations for the mocked method and passes it to the selected expectation for the duration of the invocation.getCurrentBehavior()uses that override when present, otherwise it keeps the existing per-stub call-count behavior.How to verify - mandatory
npm installnpx mocha --recursive -R dot test/src/mock-test.js --grep "returns callsFake values"npx mocha --recursive -R dot test/src/mock-test.jsnpx mocha --recursive -R dot "test/src/**/*-test.js" --timeout 10000npm run lintnpx prettier --check src/sinon/mock.js src/sinon/stub.js test/src/mock-test.jsgit diff --checkNot run locally:
npm testbecausenpm run build-artifactscurrently fails on Windows before tests withEntry module "src\create-sinon-api.js" cannot be external.Checklist for author
npm run lintpasses