Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does jasmine need sinon.js?

Tags:

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

like image 922
Jeanluca Scaljeri Avatar asked Feb 21 '13 12:02

Jeanluca Scaljeri


People also ask

What are the advantages of the Sinon JS framework?

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.

What is Sinon in JavaScript?

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.

Can you use Sinon with jest?

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.

What does Sinon spy do?

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.


1 Answers

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.

like image 108
Andreas Köberle Avatar answered Oct 02 '22 23:10

Andreas Köberle