Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support negative indices in getCall #2199

Merged
merged 2 commits into from Jan 16, 2020
Merged

Conversation

mjcrouch
Copy link
Contributor

@mjcrouch mjcrouch commented Jan 15, 2020

This allows getting calls indexed from the end of the array
e.g. -1 gets the last call, -2 gets the penultimate call etc.

Purpose (TL;DR)

Implements the proposal in #2196

Allows the user to get the -nth call when the total number of calls is arbitrary, without having to wrap around getCalls() function.

In an ideal world, the full set of calls should be known and this function would not be necessary, but for some use cases this can be useful (see #2196 for my use case). I understand this is a bit of a niche case so don't mind if you choose to close instead of merge!

How to verify

  1. Check out this branch
  2. npm install
  3. npm test

This allows getting calls indexed from the end of the array
e.g. -1 gets the last call, -2 gets the penultimate call etc.
Copy link
Contributor

@fatso83 fatso83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This was great work.

lib/sinon/proxy.js Show resolved Hide resolved
@fatso83 fatso83 merged commit 7c79e80 into sinonjs:master Jan 16, 2020
@mroderick
Copy link
Member

This has been published to npm as sinon@8.1.0

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.

None yet

3 participants