I've seen examples on the web in which people use jasmine together with sinon. However, jasmine has support for spies (which as I understand is what Sinon does). So, the question is, is Sinon still useful when using Jasmine ? If Sinon is useful what exactly makes it a good addition to jasmine ?
Cheers
sinon. js provides “[s]tandalone test spies, stubs and mocks for JavaScript.” It has no dependencies and will work with any unit testing framework. In short, they've done a lot of the work for you in writing mock servers, timers, events, and providing a framework to override the base behavior of external libraries.
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.
Sinon. js mocks ship as part of the Sinon. js library which can be plugged in and used in combination with other testing frameworks like Mocha and assertion libraries like Chai. Jest mocks, on the other hand, ship as part of the Jest framework, which also ships with its own assertions API.
Sinon spies are used to record information about function calls. Unlike mocks or stubs, spies do not replace the function being called. Spies just record what parameters the function was called with, what value it returned, and other information about the function execution.
No you dont need Sinon to work with Jasmine. But Sinon spy/mock/stubs are more convenient in some cases. There is also a minor bug in mocking setTimeout in Jasmine, which work as expected with sinon.
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