In angularjs, while testing a service, I want to check if the returned object is an Promise.
Right now I am doing the following -
obj.testMethod()
.should.be.instanceOf($q.defer());
Testing if an object is a promise is simple:
return !!obj.then && typeof obj.then === 'function';
That's it. If an object has the then
method, it's a promise.
It looks like angular's $q doesn't have anything to differentiate it from other kind of promises.
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