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 8052385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:31:56+00:00 2026-06-05T07:31:56+00:00

One of my backbone view’s initialize function contains the following code: $.when(this.broadcasters.fetch(), this.model.fetch(), this.call_types.fetch()).done(

  • 0

One of my backbone view’s initialize function contains the following code:

$.when(this.broadcasters.fetch(), 
       this.model.fetch(), this.call_types.fetch()).done(
          function(){
              do_important_stuff
          });

The results of the fetches are not relevant to the test, but the code within the block is important for the test.

My initial thought was to use jasmine-ajax, but that only supports responding to the most recent request and we actually have 3 different AJAX requests to respond to.

I can’t really mock them out because I don’t have an object to mock on (since this is an initialize function).

In the end I ended up just running the “do_important_stuff” manually, which doesn’t seem ideal since it duplicates code into the test.

Edit:

By request, how the view instance is created:

var responder = new EmailResponder({model: email, el: some_element, reply: true});
  • 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-05T07:31:59+00:00Added an answer on June 5, 2026 at 7:31 am

    You should probably try to use sinon.js. It’s great library for stubbing and mocking, including mocking XHR.
    Take a look at example:

    var Model = Backbone.Model.extend({});
    var Collection = Backbone.Collection.extend({
        model: Model,
        url: "/api/models"
    });
    
    var server = sinon.fakeServer.create();
    server.respondWith("/api/broadcasters", [
        200,
        {"Content-Type": "application/json"},
        JSON.stringify({"data": "foo"})
    ]);
    
    server.respondWith("/api/models", [
        200,
        {"Content-Type": "application/json"},
        JSON.stringify({"data": "bar"})
    ]);
    
    server.respondWith("/api/call_types", [
        200,
       {"Content-Type": "application/json"},
        JSON.stringify({"data": "baz"})
    ]);
    
    $.when($.get('/api/broadcasters'), $.get('/api/call_types'), collection.fetch()).then(function() {
        console.log('here it is!');
    });
    
    server.respond();
    

    http://jsfiddle.net/theotheo/DxVkr/

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

Sidebar

Related Questions

I'm using the following Coffeescript code to validate that initialization of one backbone.js view
I have the following code for one of my backbone views: class GD.Views.Result extends
I have two backbone Views. One is the main view and the other is
I have a backbone view - which when called presents a form $('#add-offer').click(function() {
Basically, I'm trying to do something like this: Person = Backbone.Model.extend({ validate: { ...
In one of my backbone.js view classes, I have something like: ... events: {
I'm using Backbone.js have a segmented control-type UI element for each model's view. They
suppose I have a model and a view ,ths view have two method:one is
One feature of my Backbone app involves associating models of type A with models
I keep running into this problem over and over. I have a view with

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.