Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine 2.0 rc* waits is not defined

Tags:

jasmine

Just upgraded to jasmine 2.0 rc5 from 1.3 and now all my tests that used waits() are broken because the waits() and waitsFor() function are undefined. I can't seem to find any reference to that anywhere online, is anyone aware of what is the new API to replace wait() ?

like image 230
silkAdmin Avatar asked Nov 21 '13 11:11

silkAdmin


1 Answers

Well, the usage syntax for asynchronous calls changed. You can easily see the differences between the two versions in its documentations:

Jasmine 1.3 Asynchronous support uses waitsFor() and run() functions.

According to Jasmine 2.0 Asynchronous support, these functions has been wiped out from the library. However, Jasmine 2.0 adds async support to the primitive beforeEach(), afterEach() and it() functions. The callback functions passed to these functions now can take an argument that indicates if the spec can or can't run.

Then, when you reach the necessary conditions to run your test (whenever your async job is complete), you simply call done(). And all the magic happens ;)

From the documentation:

describe("Asynchronous specs", function() {
    var value;

    beforeEach(function(done) {
        setTimeout(function() {
            value = 0;
            done();
        }, 1);
    });

    it("should support async execution of test preparation and expectations", function(done) {
        value++;
        expect(value).toBeGreaterThan(0);
        done();
    });
});

The it() spec above will run only after the setTimeout() call, because done() is called there. Note the it() callback takes an argument (done).

like image 139
Almir Filho Avatar answered Nov 03 '22 01:11

Almir Filho