Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:18:55+00:00 2026-06-17T20:18:55+00:00

I have just started using sinon.js and I am completely stumped with the terminology.

  • 0

I have just started using sinon.js and I am completely stumped with the terminology. I have used stubs where in the subview's render methods are stubbed out . But the explanation of the spy is not clear to me. Can anyone explain what exactly is the difference between these two ?

Also was wondering what the approach would be if I want to test if a new model has been added to a collection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:18:57+00:00Added an answer on June 17, 2026 at 8:18 pm

    I’m not super-familiar with sinon.js, but since these are general TDD terms and not sinon-specific ones, I think I can still answer your quesiton.

    The main difference is that a stub exists purely to “get through the code”; the stub itself doesn’t do anything except hold dummy values and methods.

    Spies on the other hand are stubs that check the values that get put in them, or the methods that get called on them. In other words, the main difference between the two is assert statements: stubs have none, while spies have some (or else they store values for asserts elsewhere in your test code).

    In other words:

    var Stub = Backbone.Model.extend();
    var stub = new Stub({value: 'test value'});
    // This can be fed to any view for testing
    
    var Spy = Backbone.Model.extend({
        initialize: function() {
            this.on('change:value', this.handleValueChange);
        },
        handleValueChange: function(value) {
            assert(!isNaN(value));
        };
        value: 'test value'
    });
    var spy = new Spy({value: 'test value'});
    // This can be fed to any view for testing AND it ensures that,
    // if that view sets its "value", that that value is a number
    

    Oh, and to answer:

    Also was wondering what the approach would be if I want to test if a new model has been added to a collection?

    Again, without getting in to Sinon specifically, there are two obvious places where you can “spy” on the model: the model itself, and its collection.

    Either you can add an event handler to (or hard-wire in to a test method on) your model which checks this.collection to determine whether/which collection its been added to. Conversely, you could bind an event or overwrite a method on the collection itself, and check this.models.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started using Html.RenderPartial(usercontrol, model) to render my user controls. Is it
we have just started using a git account of our Django website project so
I have just started using RSpec and I copied the very simple test on
I have just started using flexigrid and wanted to use the resource string to
I have just started using android, and have about 5 layout files finished. However,
i have just started using Moq ver (3.1) and i have read blogs and
I have just started using jQuery and although following code gets the job done,
I have just started using the Data Access Application Block from microsoft. There are
I have just started using C2DM. I prefer to send REGISTRATION intent only once
I have just started using Vim in a terminal (PuTTY or MinTTY), after always

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.