Mock throws exception when called twice
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 9.8k
- Forks
- 809
- PR merge metrics
- No merged PRs in 30d
Description
Description
Mock throws ExpectationError: Anonymous mock already called once when called twice, even with two preprogrammed returns()/resolves().
To Reproduce
const myMock = sinon.mock()
.returns('something')
.returns('something else');
myMock();
myMock(); // Throws 'ExpectationError: Anonymous mock already called once'
Expected behavior
Mock should be able to be reusable, as far as I know. It would be useful in case the system under test calls the function multiple times. I know this works with stubs.
Context
- Library version: 7.0.13
- Environment: Node 12.0.0
- Operating System: Windows 10
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 by locating the mock implementation and its existing tests, then reproduce the two chained returns() calls from the issue. Confirm that invoking the mock twice returns the two configured values without an ExpectationError, and add or update coverage for repeated calls.
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
- Clearly specified
- Newbie friendliness
- 48/100