Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeremyaurelius opened this issue Apr 2, 2019 · 2 comments
Open

Comments

@jeremyaurelius
Copy link

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))
@scotttrinh
Copy link
Owner

@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.

@jeremyaurelius
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants