Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Testing async calls with handlers
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Stefan  
View profile  
 More options Aug 3 2012, 3:52 am
From: Stefan <chrobot.ste...@gmail.com>
Date: Fri, 3 Aug 2012 00:52:39 -0700 (PDT)
Local: Fri, Aug 3 2012 3:52 am
Subject: Testing async calls with handlers

Hi, I'm trying to test some async code. The thing is that it's written by
me and I always have a handler whenever I have an async call:

var srv = {
    getAsync: function (handler) {
        setTimeout(function () {
            handler('success');
        }, 10);
    }

};

Do I need to mock the clock or use the runs/waitsFor to test it or is it
enough for me to put the expectations in the handlers like this:

describe('srv', function () {
    it('works', function () {
        srv.getAsync(function (x) {
            expect(x).toBe('success')
        });
    });

});

I would need to mock the clock or use runs/waitsFor if I wanted to test if
the handler was actually called, right?
If so, which of these methods (mock or runs/waitFor) is preferred?

Stefan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Doug Reeder  
View profile  
 More options Aug 3 2012, 11:21 am
From: "Doug Reeder" <reeder...@gmail.com>
Date: Fri, 03 Aug 2012 11:21:18 -0400
Local: Fri, Aug 3 2012 11:21 am
Subject: Re: [jasmine-js] Testing async calls with handlers

In general, you'll need to use waitsFor to test async code.  It sounds like you'll need to add a test jig, where your async function sets a variable that the function called by waitsFor will check.



-- Sent from my HP Pre 3



On Aug 3, 2012 10:35 AM, Stefan <chrobot.stefan@gmail.com> wrote:

Hi, I'm trying to test some async code. The thing is that it's written by me and I always have a handler whenever I have an async call:

var srv = {
    getAsync: function (handler) {
        setTimeout(function () {
            handler('success');
        }, 10);
    }
};

Do I need to mock the clock or use the runs/waitsFor to test it or is it enough for me to put the expectations in the handlers like this:

describe('srv', function () {
    it('works', function () {
        srv.getAsync(function (x) {
            expect(x).toBe('success')
        });
    });
});

I would need to mock the clock or use runs/waitsFor if I wanted to test if the handler was actually called, right?
If so, which of these methods (mock or runs/waitFor) is preferred?


Stefan

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jasmine-js/-/P1VTKj5JKY0J.
To post to this group, send email to jasmine-js@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »