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

  • Home
  • SEARCH
  • 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 8036857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:45:28+00:00 2026-06-05T02:45:28+00:00

I have a function using jQuery like so: function populate_messages_node() { $.ajax({url: /messages, type:

  • 0

I have a function using jQuery like so:

function populate_messages_node() {
    $.ajax({url: "/messages", type: "GET", success: populate_recent_messages});
}

I want to write an integration test for this function. My problem is that the test:

function test_simple() {
    populate_messages_node();
    // assert node content here
}

… will not wait for the Ajax success method (populate_recent_messages) to do its stuff. For this trivial example, doing $.ajaxSetup({async:false}) works, but I fear that will not always be true. There will be a large number of such tests for scenarios more complicated for this.

I guess my question really is: is there no way to wait on completion of XHR/Websocket operations in Javascript?

I would prefer not to modify production code (populate_messages_node), but returning the xhr result from .ajax() is prolly OK. (I apologize in advance for not having found the canonical SO post that surely describes exactly this problem.)

  • 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-05T02:45:29+00:00Added an answer on June 5, 2026 at 2:45 am

    You could return the deferred object from populate_message_node() then hook to the complete event as follows.

    function populate_messages_node() {
        return $.ajax({url: "/messages", type: "GET", success: populate_recent_messages});
    }
    
    function test_simple() {
        populate_messages_node().complete(function(jqxhr){ 
        // assert node content here
        });
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the jQuery $.ajax() function. I have put this into a parent
I have an ajax function using jQuery that defines an error function to be
I'm using jQuery 1.6.4 in a jsp and I have a function that filters
I have a function made in javascript, using jQuery. I use this to send
(using jquery) I have the following function $(function() { $('tr.parent') .css(cursor,pointer) .attr(title,Click to expand/collapse)
I have added some animation using jquery but it's not working: $('.test-container').click(function(){ $(this).css('background-color', 'rgb(119,
I have the following Javascript code (using jQuery): floatUpAndDown(); function floatUpAndDown() { $(#bird).animate({top: '+=30px'},
I have written a form using the jQuery .post() function to post the data
I have seen many js frameworks (including jquery) using closure around their main function
I have some content that I am show/hiding using the Jquery toggle function. I

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.