Friday, February 27, 2015

Stubbing Global Methods in JS Specs with Sinon

In your Rails app, your JS should be tested too! Setting that up is a topic for another post. When testing your JS, a lot of the same philosophies apply. One of those is mocking methods other than the one you're testing. How do you do this for methods in other libraries, such as vanilla JS or jQuery?

Vanilla JS (the confirm method):
 sinon.stub(window, 'confirm')  
jQuery (the fadeOut method):
 sinon.stub(jQuery.prototype, 'fadeOut')  

No comments:

Post a Comment