angular-localForage icon indicating copy to clipboard operation
angular-localForage copied to clipboard

setItem call does not return an angular promise but an ES6 promise

Open jeremyaurelius opened this issue 6 years ago • 2 comments

Screen Shot 2019-04-02 at 2 29 23 pm

As per the screenshot above, the setItem call returns an ES6 promise instead of an angular promise. This is usually not a problem, unless you plan to use the finally call on the promise, in which case you get an error.

For the sake of consistency, we should wrap the ES6 promise inside an angular promise like so:

return $q.resolve(self._localforage.setItem(self.prefix() + key, localCopy))

jeremyaurelius avatar Apr 02 '19 03:04 jeremyaurelius

@jairemix

Nice catch and sensible solution! Feel free to submit a PR, I'd be happy to review, merge, and release a patch version that fixes this.

scotttrinh avatar Apr 02 '19 14:04 scotttrinh

After delving further, it turns out a number of modern browsers actually support the finally call as per the latest ECMAScript draft, so it's not always possible to distinguish between angular promises and native promises in unit tests through the finally call.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally

Would you suggest testing for angular promises using the (private) $$state property instead?

jeremyaurelius avatar Apr 21 '19 01:04 jeremyaurelius