note35/sinon

Missing Spy API functions

Opened this issue · 2 comments

Here are some Spy API functions that are still missing:

spy.withArgs()
# Creates a spy that only records calls when the received arguments match those passed
# to withArgs. This is useful to be more expressive in your assertions, where you can access
# the spy with the same call.

spy.printf("format string", [arg1, arg2, ...])
# Returns the passed format string with the following replacements performed:
# %n
#     the name of the spy "spy" by default)
# %c
#     the number of times the spy was called, in words ("once", "twice", etc.)
# %C
#     a list of string representations of the calls to the spy, with each call prefixed by a newline and four
#     spaces
# %t
#     a comma-delimited list of this values the spy was called on
# %n
#     the formatted value of the nth argument passed to printf
# %*
#     a comma-delimited list of the (non-format string) arguments passed to printf 
  • Why not implement spy.thisValues, spy.calledOn(obj), spy.alwaysCalledOn(obj)?

I have given the explanation here

  • spy.withArgs()

This might be a little bit complicated to implement, but it's doable.

  • spy.printf("format string", [arg1, arg2, ...])

I have no idea about this to be honest, I have also never used this in SinonJS...

Ok, I'll update the issue.

Don't worry about printf, it's easy to do with regular expressions.