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
Message from discussion How to test a Deferred?

Received: by 10.42.90.4 with SMTP id i4mr3994990icm.19.1347848436001;
        Sun, 16 Sep 2012 19:20:36 -0700 (PDT)
X-BeenThere: jasmine-js@googlegroups.com
Received: by 10.231.2.13 with SMTP id 13ls13504550ibh.1.gmail; Sun, 16 Sep
 2012 19:20:35 -0700 (PDT)
Received: by 10.42.25.147 with SMTP id a19mr3934603icc.20.1347848435075;
        Sun, 16 Sep 2012 19:20:35 -0700 (PDT)
Received: by 10.42.25.147 with SMTP id a19mr3934602icc.20.1347848435058;
        Sun, 16 Sep 2012 19:20:35 -0700 (PDT)
Return-Path: <derickbai...@gmail.com>
Received: from mail-oa0-f54.google.com (mail-oa0-f54.google.com [209.85.219.54])
        by gmr-mx.google.com with ESMTPS id ar7si1532274igc.0.2012.09.16.19.20.34
        (version=TLSv1/SSLv3 cipher=OTHER);
        Sun, 16 Sep 2012 19:20:34 -0700 (PDT)
Received-SPF: pass (google.com: domain of derickbai...@gmail.com designates 209.85.219.54 as permitted sender) client-ip=209.85.219.54;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of derickbai...@gmail.com designates 209.85.219.54 as permitted sender) smtp.mail=derickbai...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-oa0-f54.google.com with SMTP id m1so7272495oag.27
        for <jasmine-js@googlegroups.com>; Sun, 16 Sep 2012 19:20:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:x-mailer
         :mime-version:content-type;
        bh=OqSC0zwDwlGsH6DcIgav7GH0Vfc8XFe3qqtXUN/xJN8=;
        b=tvNZIv1/igO7Hrjtt0yHwNtaUD+s0N/ENbTBDBDzEbUGZhk4QXbBWqJOMXvi0PxOwq
         R1bzs2/UFv6PiroMuI13NrXb5Ejsv9XsPCwSHrobMRxh6RZxA9WbGzta0IH8AjgSJXJa
         Pkxll5845eRqsC/YwK5dGKNTpeSH5+1qKTU3oATDkNTpafyZVt0r++vY5V5QptyKJssr
         ekU09O8XEBQ4TGdIJTQaEjVFVs/LpV1UAw8d+3VFfO4AdVNab+yscqSxaYAiRz8+creT
         Nq6y/hFUgM+ujxHJRcMVPv0zG+bFY4pej0z6S3Uv8O0hUgERFMpIOeEoB090n0rQZ6zf
         zTkw==
Received: by 10.60.25.226 with SMTP id f2mr10054127oeg.53.1347848434800;
        Sun, 16 Sep 2012 19:20:34 -0700 (PDT)
Return-Path: <derickbai...@gmail.com>
Received: from [192.168.1.134] (216-188-241-10.dyn.grandenetworks.net. [216.188.241.10])
        by mx.google.com with ESMTPS id a20sm7387185oei.2.2012.09.16.19.20.32
        (version=TLSv1/SSLv3 cipher=OTHER);
        Sun, 16 Sep 2012 19:20:33 -0700 (PDT)
Date: Sun, 16 Sep 2012 21:20:31 -0500
From: Derick Bailey <derickbai...@gmail.com>
To: jasmine-js@googlegroups.com
Message-ID: <01A7AD3BD08F4F9BB5E01043C06B1...@gmail.com>
In-Reply-To: <ebd22141-c11f-4500-b184-bc5dad6056ea@googlegroups.com>
References: <ebd22141-c11f-4500-b184-bc5dad6056ea@googlegroups.com>
Subject: Re: [jasmine-js] How to test a Deferred?
X-Mailer: sparrow 1.6.3 (build 1172)
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="505688ef_3deb451a_640b"

--505688ef_3deb451a_640b
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I wrote up a blog post on this, and how to make it less painful: http://lostechies.com/derickbailey/2012/08/18/jasmine-async-making-asynchronous-testing-with-jasmine-suck-less/ 

The use of "setTimeout" vs a deferred makes no difference in how the test looks.

You can see an example of my own tests against deferreds with Jasmine and my Jasmine.Async add-on, here: https://github.com/derickbailey/bbclonemail/blob/master/spec/javascripts/mail.spec.js 

I also have a post that shows more about unit testing async code, here: http://lostechies.com/derickbailey/2012/08/17/asynchronous-unit-tests-with-mocha-promises-and-winjs/ - this deals with Mocha, but with my Jasmine.Async add-on, the test implementation caries over almost perfectly.

Hope that helps.

  -- Derick

Derick Bailey
- @derickbailey (http://twitter.com/derickbailey) 
- http://derickbailey.lostechies.com (http://DerickBailey.LosTechies.com)
- http://watchmecode.net 

Muted Solutions, LLC
- @mutedsolutions (http://twitter.com/mutedsolutions)
- http://mutedsolutions.com 
- http://backbonetraining.net


On Sunday, September 16, 2012 at 7:04 PM, jspeaks wrote:

> I am looking for a terse example of how to test a Deferred with Jasmine.  I basically want to validate the done result.  A clear example would be appreciated.
> 
> >> Neighborhood.js <<
> Neighborhood = function(){
>   var me = {};
> 
>   me.updates = function(){
>     var def = $.Deferred();
> 
>     setTimeout(def.resolve([{"aaa",200},{"bbb",300}]), 1000*5);
> 
>     return def.promise();
>   };
> 
>   return me;
> }
> 
> >> App.js <<
> $(function(){
>   var neighborhood = Neighborhood();
>   neighorhood.updates().done(function(data){ console.log(data) });
> })
> 
> I reviewed all the asynchronous examples, but I still don't have a clear understanding of how to test the result of a deferred in a terse manner.
> 
> Thanks in advance for an example,
> 
> Jaye Speaks
> @jspeaks
> -- 
> 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/-/v9PZHXyBAJoJ.
> To post to this group, send email to jasmine-js@googlegroups.com (mailto:jasmine-js@googlegroups.com).
> To unsubscribe from this group, send email to jasmine-js+unsubscribe@googlegroups.com (mailto:jasmine-js+unsubscribe@googlegroups.com).
> For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.


--505688ef_3deb451a_640b
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


                <div>
                    I wrote up a blog post on this, and how to make it le=
ss painful:&nbsp;<a href=3D=22http://lostechies.com/derickbailey/2012/08/=
18/jasmine-async-making-asynchronous-testing-with-jasmine-suck-less/=22>h=
ttp://lostechies.com/derickbailey/2012/08/18/jasmine-async-making-asynchr=
onous-testing-with-jasmine-suck-less/</a>
                </div><div><br></div><div>The use of =22setTimeout=22 vs =
a deferred makes no difference in how the test looks.</div><div><br></div=
><div>You can see an&nbsp;example of my own tests against deferreds with =
Jasmine and my Jasmine.Async add-on, here:&nbsp;<a href=3D=22https://gith=
ub.com/derickbailey/bbclonemail/blob/master/spec/javascripts/mail.spec.js=
=22>https://github.com/derickbailey/bbclonemail/blob/master/spec/javascri=
pts/mail.spec.js</a></div>
                <div><div><br></div><div>I also have a post that shows mo=
re about unit testing async code, here:&nbsp;<a href=3D=22http://lostechi=
es.com/derickbailey/2012/08/17/asynchronous-unit-tests-with-mocha-promise=
s-and-winjs/=22>http://lostechies.com/derickbailey/2012/08/17/asynchronou=
s-unit-tests-with-mocha-promises-and-winjs/</a>&nbsp;- this deals with Mo=
cha, but with my Jasmine.Async add-on, the test implementation caries ove=
r almost perfectly.</div><div><br></div><div>Hope that helps.</div><div><=
br></div><font face=3D=22arial=22 size=3D=222=22><span style=3D=22font-fa=
mily: Helvetica; font-size: 13px; =22>&nbsp; -- Derick<br><br><b>Derick B=
ailey</b><br><span style=3D=22color: rgb(0, 0, 153); =22>-&nbsp;</span><a=
 href=3D=22http://twitter.com/derickbailey=22 target=3D=22=5Fblank=22 sty=
le=3D=22color: rgb(0, 0, 153); =22>=40derickbailey</a>&nbsp;<br style=3D=22=
color: rgb(0, 0, 153); =22><span style=3D=22color: rgb(0, 0, 153); =22>-&=
nbsp;</span><a href=3D=22http://DerickBailey.LosTechies.com=22 target=3D=22=
=5Fblank=22 style=3D=22color: rgb(0, 0, 153); =22>http://derickbailey.los=
techies.com</a></span></font><div>- <a href=3D=22http://watchmecode.net=22=
>http://watchmecode.net</a>&nbsp;<font face=3D=22arial=22 size=3D=222=22>=
<span style=3D=22font-family: Helvetica; font-size: 13px; =22><br><br><b>=
Muted Solutions, LLC</b><br><span style=3D=22color: rgb(0, 0, 153); =22>-=
&nbsp;</span><a href=3D=22http://twitter.com/mutedsolutions=22 target=3D=22=
=5Fblank=22 style=3D=22color: rgb(0, 0, 153); =22>=40mutedsolutions</a><b=
r style=3D=22color: rgb(0, 0, 153); =22><span style=3D=22color: rgb(0, 0,=
 153); =22>-&nbsp;</span><a href=3D=22http://mutedsolutions.com=22 target=
=3D=22=5Fblank=22 style=3D=22color: rgb(0, 0, 153); =22>http://mutedsolut=
ions.com</a>&nbsp;<br><div><span style=3D=22color: rgb(0, 0, 153); =22>-&=
nbsp;</span><font color=3D=22=23003cff=22><a href=3D=22http://backbonetra=
ining.net=22>http://backbonetraining.net</a></font></div></span></font></=
div><div><br></div></div>
                =20
                <p style=3D=22color: =23A0A0A8;=22>On Sunday, September 1=
6, 2012 at 7:04 PM, jspeaks wrote:</p>
                <blockquote type=3D=22cite=22 style=3D=22border-left-styl=
e:solid;border-width:1px;margin-left:0px;padding-left:10px;=22>
                    <span><div><div>I am looking for a terse example of h=
ow to test a Deferred with Jasmine.&nbsp; I basically want to validate th=
e done result.&nbsp; A clear example would be appreciated.<br><br>&gt;&gt=
; Neighborhood.js &lt;&lt;<br>Neighborhood =3D function()=7B<br>&nbsp; va=
r me =3D =7B=7D;<br><br>&nbsp; me.updates =3D function()=7B<br>&nbsp;&nbs=
p;&nbsp; var def =3D =24.Deferred();<br><br>&nbsp;&nbsp;&nbsp; setTimeout=
(def.resolve(=5B=7B=22aaa=22,200=7D,=7B=22bbb=22,300=7D=5D), 1000*5);<br>=
<br>&nbsp;&nbsp;&nbsp; return def.promise();<br>&nbsp; =7D;<br><br>&nbsp;=
 return me;<br>=7D<br><br>&gt;&gt; App.js &lt;&lt;<br>=24(function()=7B<b=
r>&nbsp; var neighborhood =3D Neighborhood();<br>&nbsp; neighorhood.updat=
es().done(function(data)=7B console.log(data) =7D);<br>=7D)<br><br>I revi=
ewed all the asynchronous examples, but I still don't have a clear unders=
tanding of how to test the result of a deferred in a terse manner.<br><br=
>Thanks in advance for an example,<br><br>Jaye Speaks<br>=40jspeaks<br>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups=
 =22Jasmine=22 group.<br>
To view this discussion on the web visit <a href=3D=22https://groups.goog=
le.com/d/msg/jasmine-js/-/v9PZHXyBAJoJ=22>https://groups.google.com/d/msg=
/jasmine-js/-/v9PZHXyBAJoJ</a>.<br> =20
To post to this group, send email to <a href=3D=22mailto:jasmine-js=40goo=
glegroups.com=22>jasmine-js=40googlegroups.com</a>.<br>
To unsubscribe from this group, send email to <a href=3D=22mailto:jasmine=
-js+unsubscribe=40googlegroups.com=22>jasmine-js+unsubscribe=40googlegrou=
ps.com</a>.<br>

=46or more options, visit this group at <a href=3D=22http://groups.google=
.com/group/jasmine-js=3Fhl=3Den=22>http://groups.google.com/group/jasmine=
-js=3Fhl=3Den</a>.<br>


</div></div></span>
                =20
                =20
                =20
                =20
                </blockquote>
                =20
                <div>
                    <br>
                </div>
            
--505688ef_3deb451a_640b--