Conversation
Reject individual spy calls in calledOnce and calledOnceWithExactly with a clear assertion error while preserving calledWithExactly support for individual calls. Correct the documentation to describe the whole-spy contract. Fixes sinonjs#2277.
This branch has not been deployed
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
Reject individual spy calls in
calledOnceandcalledOnceWithExactlywith a clear diagnostic rather than a misleading assertion failure. Correct the documentation to require a whole spy and direct individual-call checks tocalledWithExactly.Fixes #2277.
Validation limits: The unchanged Rollup configuration fails on Windows before producing artifacts, so the configured Node suite, distribution contracts, browser/WebWorker tests, and documentation tests remain unverified. Full Prettier checking reports 85 unchanged files with CRLF-only differences; all three changed files pass.
Implementation and validation
This follows the historical maintainer direction to correct the documentation and reject calls, not implement the original request to accept them. It does not imply new maintainer approval.
The shared fake and assertion-arity checks still run first. Only the two spy-only assertions then require a function and report failures through the existing
failAssertionhelper. This preserves custom and exposed failure handlers, avoids falsely rejecting spies with aproxyproperty, and leaves supported individual-call assertions unchanged. No exports, overloads, source-layout changes, dependencies, or public API manifest changes are introduced.Validation used Windows, Node 26.3.0, and npm 11.16.0:
npm run test-node, which stops in its build prerequisite.proxyproperties, default/custom/nonthrowing/exposed failure handlers, and validcalledWithExactlycall-level behavior. Existing argument-diff tests continue to pass.npm run lintpasses with a per-command PowerShell script-shell override; the default Windows command shell passes literal quotes in the ESLint glob. The changed JavaScript files also pass direct ESLint.Entry module "src\create-sinon-api.js" cannot be external. The build script, Rollup configuration, dependency manifests, and public API manifest have identical Git blobs to the base commit. A direct control confirms that the unchanged configuration classifies its own first Windows entry as external.How to verify - mandatory
HUSKY=0andHUSKY_SKIP_INSTALL=1in the command environment, then install locked dependencies withnpm ci.npm run test-node,npm run lint,npm run prettier:check, andnpm run test-contracton a host where the existing build prerequisites work.Checklist for author
npm run lintpassesNo new standard-library method references are introduced in production code.