3

It seems straightforward to create a stub that returns different values on repeated calls: Possible to stub method twice within a single test to return different results?

But, I how does one do this with an async method that resolves on multiple calls?

sinon(module, "myFunction")
  .resolves('a')
  .resolves('b')

To be clear, in the fragment above, the second resolves overwrites the first, so it always returns 'b'. I'd like the behavior where 'myFunction' first resolves 'a' and then resolves 'b'.

Kurt
  • 399
  • 3
  • 14

1 Answers1

8

Here's the solution:

sinon(module, "myFunction")
  .onFirstCall().resolves('a')
  .onSecondCall().resolves('b')
Kurt
  • 399
  • 3
  • 14