I need to write a test for a function that has a setTimeout()
call inside, but i can\'t find how i should do.
This is the function
// Di
Since Jasmine 2 the syntax has changed: http://jasmine.github.io/2.0/introduction.html#section-Asynchronous_Support
You now can simply pass a done
callback to beforeEach
, it
, and afterEach
:
it('tests something async', function(done) {
setTimeout(function() {
expect(somethingSlow).toBe(true);
done();
}, 400);
});
Update: Since writing this it's now also possible to use async/await
which would be my preferred approach.