Skip to content
New issue

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

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

Already on GitHub? # to your account

Unhandled Promise rejections from instanceof check #132

Closed
metrip opened this issue Apr 24, 2018 · 2 comments
Closed

Unhandled Promise rejections from instanceof check #132

metrip opened this issue Apr 24, 2018 · 2 comments

Comments

@metrip
Copy link

metrip commented Apr 24, 2018

The handleRequest function checks for result.then instanceof Function to determine if a Promise result is returned from the handler, in https://github.com/ctimmerm/axios-mock-adapter/blob/master/src/handle_request.js#L52

This does not seem to be correct, as this is not true for returned rejected promises in all environments; in my case Node.js 8.10. I'm using adapter.onGet(...).timeout() and I see:

image

This leads to the flow going to utils.settle instead of result.then, the promise not getting handled and erroring, and the original error getting lost, which is bad.

Possibly related: #122

I believe adding the typeof check would do the intended functionality correctly here?

@ctimmerm
Copy link
Owner

Do you think you could write a failing test case for it?

@metrip
Copy link
Author

metrip commented Apr 27, 2018

On further inspection, it is not a feature of Node, but somehow specific to the VM that Jest sets up - Promise objects look a little different there, but I can't really tell why. Could be occurring in VM's created by other test frameworks, but I haven't had a look at them.

Writing test cases seems difficult as I can't find a good way to simulate functions like this.

However, as the intent here seems to be "if result.then is callable, settle result like a Promise", so the solution should be simple somehow.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants