Does jasmine need sinon.js?

余生颓废 提交于 2019-12-04 15:33:38

问题


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


回答1:


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.




回答2:


I use Sinon with Jasmine for it's fakeServer capabilities. Sinon allows me to easily mock AJAX HTTP requests without relying on the state of my server. Sinon also provides lower-level http mocking functionality for when you really need to fine-tune your mocked services.




回答3:


You can use SinonJS as an extension to Jasmine. Sinon has a very nice API for a mock server which is quite handy if you want to test REST calls without having a real backend. There is also a nice documentation which shows the combination of SinonJS with Jasmine.



来源:https://stackoverflow.com/questions/15002541/does-jasmine-need-sinon-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!