Async testing problem

70 views
Skip to first unread message

sambit...@perceptivesoftware.com

unread,
Jan 13, 2015, 2:01:14 AM1/13/15
to jasmine...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages