Skip to content

fix: share call order with stub instances - #2764

Closed
wangxpych wants to merge 1 commit into
sinonjs:mainfrom
wangxpych:fix/stub-instance-call-order
Closed

fix: share call order with stub instances#2764
wangxpych wants to merge 1 commit into
sinonjs:mainfrom
wangxpych:fix/stub-instance-call-order

Conversation

@wangxpych

Copy link
Copy Markdown

Fixes #2760.

Problem

The per-sandbox callId context added for parallel-test isolation is passed through spy(), stub(), and fake(), but createStubInstance() still creates its method stubs with the module-level default context. Comparisons against other fakes from the same sandbox can therefore report the wrong call order.

Changes

  • Thread the sandbox context through createStubInstance() when its methods are stubbed.
  • Route the root sinon.createStubInstance() wrapper through its backing root sandbox so it uses the same context as root spies and stubs.
  • Add regression coverage for both the root API and explicit sandboxes, placing a stub-instance call between two spy calls.

Verification

  • npm test — Node: 1,558 passing / 12 pending; headless browser: 1,551 passing / 13 pending; WebWorker: 1 passing
  • npm run lint
  • npm run prettier:check
  • npm run test-contract
  • npm run check-dependencies

Thread each sandbox's callId context through createStubInstance so its generated methods can be ordered against spies and stubs from the same sandbox. Preserve the root API wrapper while routing it through its backing sandbox.

Fixes #2760
@wangxpych

Copy link
Copy Markdown
Author

Withdrawing this contribution after re-evaluating the repository's recent human review and merge activity. No action is needed from maintainers. Thank you.

@wangxpych wangxpych closed this Sep 2, 2026
@wangxpych
wangxpych deleted the fix/stub-instance-call-order branch September 2, 2026 16:47
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.

createStubInstance() doesn't receive per-sandbox callId context, breaking calledAfter/calledBefore vs spy()

1 participant