Search code examples
javascriptsinonassertionssinon-chaicypress

Cypress `onCall()` assertion support seems not documented?


In this cypress example I find onCall() method which seems to be 'Sinon', as I find it here. The supported assertions in Cypress are mentioned here and it includes sinon-chai, which does not mention onCall().

My question: what assertions are supported exactly, as onCall() support seems not documented?


Solution

  • Cypress stubs and spies are really just sinon stubs and spies, albeit with a bit more functionality that only exists in Cypress.

    However, the underlying instances returned are from sinon and therefore as stated in the docs, all methods from sinon are available on these instances.

    https://docs.cypress.io/api/commands/stub.html#Yields

    onCall comes from sinon - it is not an assertion - it's just a method you'd call on a stub/spy to access the things as part of that invocation.

    That's why it's not documented in the assertions - there are a variety of other useful methods beyond just this one and I would reference sinons docs to see how you'd use them.

    Look for the onCall method in these docs here: http://sinonjs.org/releases/v4.5.0/stubs/

    To answer the question: what assertions are supported exactly it is what is documented in the guides here: https://docs.cypress.io/guides/references/assertions.html#Sinon-Chai