Stubbing Backbone.js fetch with Jasmine & Sinon.js

Posted on October 3, 2011

I needed to stub out a Backbone collection’s fetch method and make it return success. I’m using Jasmine BDD for the testing framework and Sinon.js for stubbing the methods. Here’s how I did it:


3 Replies to "Stubbing Backbone.js fetch with Jasmine & Sinon.js"

  • Ryan Fischer
    January 24, 2013 (1:10 pm)
    Reply

    I just wanted to say 2 years later and this is still helpful! It is exactly what I was looking for. Thanks!

    • Rebecca
      February 11, 2013 (11:46 am)
      Reply

      Glad to hear it!

  • Dale Matthews
    April 7, 2016 (1:04 pm)
    Reply

    After you posted this, Sinon 1.4.0 added async versions of those function calls. So yieldsToAsync may be a better use for fetch.


Got something to say?

Some html is OK

This site uses Akismet to reduce spam. Learn how your comment data is processed.