0

Given angular controller with function

this.checkResponse = function (response) {
  if (response.success === true) {
    return $q.resolve(response);
  } else {
    return $q.reject(response);
  }
};

how do I test with Jasmine that returned value is a promise? I can easily verify that I called resolve or reject inside a function, or that I receive jasmine.any(Function), but how do I ensure that it's a promise?

Konstantin
  • 55
  • 10

1 Answers1

1

I'd do like this in my tests:

//done callback will ensure that success function should called
it('blabla', function(done){
    //when 
    app.checkResponse().then(function(){
        done();
    }, function(){
        fail("error callback has been called");
        done();
    });
})

It will ensure that you have to return with a promise, otherwise it'll fail with timeout. For me this is the quickest solution.

Is that what you are looking for? Or did I misunderstood you?

Iamisti
  • 1,680
  • 15
  • 30
  • Yes, it looks like what I might need and I also though of a similar approach, but for some reason I was sure that there might be something more elegant. – Konstantin Jan 06 '16 at 15:33
  • I use this approach in my project. I don't know any more elegant solution. – Iamisti Jan 06 '16 at 15:37