Sinon

spy

sinon.spy()
  • function that records invocations
  • can wrap existing methods or not
    • if wrapping an existing method, will pass through to the real implementation, and will record return value
    • if not, then there is no existing behavior to pass through to
    • seems identical to a stub in that case then
  • is it related to not being able to specify return value?

stub

sinon.stub().resolves()
  • superset of spies’ functionality
  • spies with pre-programmed behavior
    • returns()
    • resolves()
    • throws()
    • rejects()
  • can wrap existing methods or not
  • but existing methods are never called

mock

  • superset of stubs’ functionality
  • you pre-program the expectations too

fake

pre-program behavior and make assertions. unclear how this differs from stub

sinon.fake.returns(…);
sinon.fake.resolves(…);