How can I test sequence of function calls by Sinon.js?
For example i have three (3) handlers in object, and want define sequence of handler calls. Is there any possibilities for this?
The sinon. stub() substitutes the real function and returns a stub object that you can configure using methods like callsFake() . Stubs also have a callCount property that tells you how many times the stub was called. For example, the below code stubs out axios.
A test spy is a function that records arguments, return value, the value of this and exception thrown (if any) for all its calls.
Wrapping a test with sinon. test() allows us to use Sinon's sandboxing feature, allowing us to create spies, stubs and mocks via this.
Sinon JS is a popular JavaScript library that lets you replace complicated parts of your code that are hard to test for “placeholders,” so you can keep your unit tests fast and deterministic, as they should be.
http://sinonjs.org/docs/
sinon.assert.callOrder(spy1, spy2, ...)
Passes if the provided spies where called in the specified order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With