You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have troubles in bigger codebase, where we use both request and rp, but in jest environment regular request module gets extended with request-promise and promise interface, changing all regular requests (made by request) to be promises and causing unhandled rejections.
Simplest testcase I could come up with:
constrequest=require('request');constrp=require('request-promise-native');test('request does not have promise interface',()=>{expect(Object.is(request.Request.prototype.init,rp.Request.prototype.init)).toBe(false);})
When I run in node (outside of jest environment), assertion passes, meaning the init method is not replaced for regular request module.
It seems that the issue happens when request is required before request-promise-native.
If the order of require statements is changed to the opposite the assertion passes.
This module (jest-transform-stealthy-require) relies on jest.isolateModules() to resolve conflicts between the imported modules. if you use request directly unfortunately the order of imports matters due to this issue: jestjs/jest#7863
I would suggest changing the order of require statements in your codebase so that request-promise-native is imported before request if that is possible.
Hello,
I have troubles in bigger codebase, where we use both request and rp, but in jest environment regular request module gets extended with request-promise and promise interface, changing all regular requests (made by
request
) to be promises and causing unhandled rejections.Simplest testcase I could come up with:
When I run in node (outside of jest environment), assertion passes, meaning the init method is not replaced for regular
request
module.Is it possible to fully separate
request
fromrequest-promise
in jest environment?The text was updated successfully, but these errors were encountered: