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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:32:10+00:00 2026-06-10T00:32:10+00:00

These days I’m trying to put up some tests for my first serious Backbone

  • 0

These days I’m trying to put up some tests for my first serious Backbone app. I had no problem so far with normal test but now I’m stuck trying to setting up an async test.

Basically my server API return a page with a 500 HTTP code error if I try to save a model with invalid attributes and I want to check if this trigger the right “error” state in Backbone.

I’ve tried to set-up the test in this way:

asyncTest("Test save Model function", function(){
        expect(1);

        var user = new User({});

        var err_spy = this.spy();
        user.on('error',err_spy);         

        user.save(user,{error:function(){
            start();
            equal( err_spy.callCount, 1, "Callback 'error' called once");

        }});

    });

The problem is that the error callback of the save function overrides the one in the model, so the only way to trigger it would be to do it manually:

user.trigger("error");

I don’t think it is a right way to test because in my production environment there is no error callback for model’s save function, but on the other hand I don’t know how to tell Qunit to wait the ajax response to evaluate the test assertion.

Can someone suggest me a way to make it work? Thank you!

  • 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-10T00:32:11+00:00Added an answer on June 10, 2026 at 12:32 am

    Something like this should do the trick. I’m going from memory here, but the sinon fake server should allow you to immediately return the 500 error state and subsequently invoke the spied-on function. You might need to tweak the server.respondWith(…) call.

    asyncTest("Test save Model function", function(){
                expect(1);
    
                var user = new User({});
    
                // Set up a fake 500 response.
                var server = sinon.fakeServer.create();
                server.respondWith(500, {}, "");
    
                // Create the error callback.
                var err_callback = function(){};
    
                var err_spy = sinon.spy(err_callback);         
    
                user.save(user, {error: err_callback});
    
                server.respond();
    
                equal( err_spy.callCount, 1, "Callback 'error' called once");
    
                server.restore();
    
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

These days I design some algorithms in python, but find first two greatest value
These days, we encountered a strange problem, some of our solr apps on tomcat
in these days i'm playing with thread library and trying to implement some functions.
I installed integrity app these days. and found some issues. I follow this. $
These days, I use Flex & Bison generated some codes to develop a SQL-parser
These days I'm facing a problem with encoding string from an array of byte.
During these days I had to develop applications involved in xml schemas definitions. Well,
Playing around with Google Maps these days, with some directions. I have a map
These days I have learned some basic usage of C#. I think that because
i'm into rspec these days, trying to make my models more precise and accurate.

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.