Re: [jasmine-js-dev] Async testing problem

1,874 views
Skip to first unread message

Davis Frank

unread,
Jan 13, 2015, 12:29:44 PM1/13/15
to jasmi...@googlegroups.com
+jasmi...@googlegroups.com

(this group is for help with using Jasmine)

--dwf

On Mon, Jan 12, 2015 at 11:01 PM, <sambit...@perceptivesoftware.com> wrote:
Hi

I have taken following code from http://jasmine.github.io/2.0/introduction.html :

"use strict";

define([],
        function() {
            describe("Asynchronous specs", function() {
                var value = 0, originalTimeout = 0;
                beforeEach(function(done) {
                    originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
                    jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
                    console.log('Time when beforeeach got invoked : '+(new Date()).getTime());
                    setTimeout(function() {
                        value ++;
                        console.log('Time when timer fired in beforeeach : '+(new Date()).getTime());
                        done();
                    }, 1000);
                });
                
                afterEach(function(done){
                    jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
                });

                it("should support async execution of test preparation and expectations", function(done) {
                    console.log('Time when testcase got invoked : '+(new Date()).getTime());
                    expect(value).toBeGreaterThan(0);
                    done();
                });
            });
        });


Test case failed with following error : Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
The console log that I got : 

[Log] Time when beforeeach got invoked : 1421131668407 
[Log] Time when testcase got invoked : 1421131668909 
[Log] Time when timer fired in beforeeach : 1421131669409 
[Log] Time when testcase got invoked : 1421131669409 

Testcase invoked two times. 

It would be nice if you point out what I am missing?

Regards,
Sambit Sarkar

--
You received this message because you are subscribed to the Google Groups "Jasmine Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js-de...@googlegroups.com.
To post to this group, send email to jasmine...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js-dev.
For more options, visit https://groups.google.com/d/optout.

Gregg Van Hove

unread,
Jan 13, 2015, 8:50:53 PM1/13/15
to jasmi...@googlegroups.com
How are you running jasmine? What version of jasmine are you using?

The error you're seeing is because your `afterEach` accepts a `done` argument but never calls it. 

-Gregg

You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
Reply all
Reply to author
Forward
0 new messages