sinon.assert.calledOnceWithExactly() does not accept a single spy call
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 9.8k
- Forks
- 809
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
According to the v9.0.2 documentation, sinon.assert.calledOnceWithExactly() can accept a single, dedicated spy call, instead of a spy. However, it throws an error instead:
const sinon = require("sinon");
let add = sinon.fake((a, b) => a + b);
add(5, 100);
// Passes
sinon.assert.calledOnceWithExactly(add, 5, 100);
// Passes
sinon.assert.calledWithExactly(add.getCall(0), 5, 100);
// Should pass, but throws in v9.0.2
sinon.assert.calledOnceWithExactly(add.getCall(0), 5, 100);
The exception message:
C:\Users\<username>\Documents\GitHub\test-proj\node_modules\sinon\lib\sinon\assert.js:110
throw error;
^
Error [AssertError]: expected fake(5, 100) => 105 at Object.<anonymous> (C:\Users\<username>\Documents\GitHub\test-proj\index.js:4:1) to be called once and with exact arguments
at Object.fail (C:\Users\<username>\Documents\GitHub\test-proj\node_modules\sinon\lib\sinon\assert.js:107:21)
at failAssertion (C:\Users\<username>\Documents\GitHub\test-proj\node_modules\sinon\lib\sinon\assert.js:66:16)
at Object.assert.<computed> [as calledOnceWithExactly] (C:\Users\<username>\Documents\GitHub\test-proj\node_modules\sinon\lib\sinon\assert.js:92:13)
at Object.<anonymous> (C:\Users\<username>\Documents\GitHub\test-proj\index.js:7:14)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
To Reproduce
Steps to reproduce the behavior:
- Create a fake method with
sinon.fake() - Call the fake method a number of times
- Call
sinon.assert.calledOnceWithExactly(), passing a dedicated spy call usinggetCall(), and specify the correct arguments. - Assertion error is raised
Expected behavior
sinon.assert.calledOnceWithExactly() should pass it normally.
Context (please complete the following information):
- Library version: v9.0.2
- Environment: Node.js 12.18.2 / Windows 10 (x86-64)
- Example URL: (none)
- Other libraries you are using: Mocha
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at lib/sinon/assert.js, the assertion entry point shown in the error trace, and reproduce the reported case with sinon.fake(), getCall(0), and calledOnceWithExactly(). Add coverage for the dedicated spy-call form and confirm that the assertion passes with the exact arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100