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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:35:03+00:00 2026-05-24T16:35:03+00:00

I am writing a mock for the node-redis module and using Jasmine to test

  • 0

I am writing a mock for the node-redis module and using Jasmine to test it. I write tests for various aspects of Redis commands and my intention is to be able to run the tests against the original Redis module as well.

My problem is: if I understood node-redis correctly, the returned value of the asynchronous functions of node-redis is different depending upon the command was sent to Redis or queued for sending later (for example, to be sent after the connection is complete). But I would like to test the returned value, too, and if I write a test such as the one below:

it("should update value", function () {
  var client = redis.createClient();
  client.set("key", "1st");
  var value = client.get("key", function (err, data) {
    expect(err).toBeNull();
    expect(data).toBe("1st");
  });
  expect(value).toBe(true);
});

it will not pass if I use the real Redis module, because there will not be enough time to connect to database.

Is there a way to wait the asynchronous request to be executed to go ahead testing the code?

(Answers with different approaches to this problem are welcomed too.)

  • 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-05-24T16:35:04+00:00Added an answer on May 24, 2026 at 4:35 pm

    expect(err).toBeNull() == expect(value).toBe(true); because asynchronous functions return nothing (undefined). You should do this only

    client.set("key", "1st");
    client.get("key", function (err, data) {
      expect(err).toBeNull();
      expect(data).toBe("1st");
    });
    

    But if you want to wait you should use something like this:

    var value = undefined;
    client.get("key", function (err, data) {
      expect(err).toBeNull();
      expect(data).toBe("1st");
      value = true;
    });
    setInterval(function(){ expect(value).toBe(true); }, 10000); // wait 10 seconds for connection
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing some tests for a Magento module, using Ivan Chepurnyi's extension ,
I'm writing a test app using the twitter gem and I'd like to write
Many people use Mock Objects when they are writing unit tests. What is a
I'm writing unit tests for a module in a small Javascript application. In order
Is it common to write integration tests before writing unit tests? Is it conventional,
Know of a way to mock %[]? I'm writing tests for code that makes
I'm writing a unit test with a mock and I'm having trouble writing it
When it comes to writing unit testing for UI what do you write test
I'm writing a unit test of my mock-up repositoy. While the real repository lays
I have used Rhino.Mocks extensively currently writing some tests in Java using EasyMocks. However

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.