0
votes

my function in the service is

listo: function () {
          var deferred = $q.defer();

          setTimeout(function () {
            deferred.resolve(true);

          }, 2000);

          return deferred.promise;
}

in jasmine test I have

describe("testeando local storage", function () {

  var bd;

  beforeEach(module('modulo'));

  beforeEach(inject(function (bds) {
    bd = bds;
  }));

  beforeEach(function () {
    expect(bd).toBeDefined();
  });

  var valor;

  it("prueba",function(done){
    bd.listo().then(function(res) {
      valor = res;
      done();
    })
  });

  it("pruebita", function(done) {
    expect(valor).toBe(true);
    done();
  });


});

I got the following error:

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

PhantomJS 2.1.1 (Linux 0.0.0) testeando local storage should support async execution of test preparation and expectations FAILED Expected undefined to be true.

1

1 Answers

0
votes

Try to set delay parameter for that test to be more than 2000 ms:

it("prueba",function(done){
  bd.listo().then(function(res) {
    valor = res;
    done();
  })
}, 3000);

Also you may try to do it for whole the spec:

beforeEach(function() {
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
});