jasmine: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL jasmine: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL javascript javascript

jasmine: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL


Having an argument in your it function (done in the code below) will cause Jasmine to attempt an async call.

//this block signature will trigger async behavior.it("should work", function(done){  //...});//this block signature will run synchronouslyit("should work", function(){  //...});

It doesn't make a difference what the done argument is named, its existence is all that matters. I ran into this issue from too much copy/pasta.

The Jasmine Asynchronous Support docs note that argument (named done above) is a callback that can be called to let Jasmine know when an asynchronous function is complete. If you never call it, Jasmine will never know your test is done and will eventually timeout.


Even for async tests, there is a timeout that goes off in this cases, You can work around this error by increasing the value for the limit timeout to evaluate an async Jasmine callback

describe('Helper', function () {    var originalTimeout;    beforeEach(function() {        originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;        jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000;    });    afterEach(function() {      jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;    });    it('Template advance', function(doneFn) {        $.ajax({            url: 'public/your-end-point.mock.json',            dataType: 'json',            success: function (data, response) {                // Here your expected using data                expect(1).toBe(1)                doneFn();            },            error: function (data, response) {                // Here your expected using data                expect(1).toBe(1)                doneFn();            }        });    });});

Source: http://jasmine.github.io/2.0/introduction.html#section-42


This error can also be caused by leaving out inject when initializing a service/factory or whatever. For example, it can be thrown by doing this:

var service;beforeEach(function(_TestService_) {    service = _TestService_;});

To fix it just wrap the function with inject to properly retrieve the service:

var service;beforeEach(inject(function(_TestService_) {    service = _TestService_;}));