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() ?
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With