Request object is not defined on response
See original GitHub issueconst axiosMock = new MockAdapter(axios);
axiosMock.onGet(`${gl.TEST_HOST}/test`).reply(200, { some: 'data' });
axios.get(`${gl.TEST_HOST}/test`)
.then(response => console.log(response.request));
will result in undefined.
This makes it impossible to test code which handles multiple routes and checks for the incoming request.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Response object is not defined when passed in a function
The issue is that response object passed from express route is not defined in get_user_statuses function. Now I have two question:.
Read more >Why is response not defined? (Example) - Treehouse
Why is response not defined? I am running node app.js, but I keep getting an error: ReferenceError: response is not defined ...
Read more >fetch() - Web APIs | MDN
The global fetch() method starts the process of fetching a resource from the network, returning a promise which is fulfilled once the response...
Read more >TypeError: response.json is not a function in JavaScript
The "response.json is not a function" error occurs when we call the json() method on an object that is not the Response object...
Read more >urllib.request — Extensible library for opening URLs — Python ...
Source code: Lib/urllib/request.py The urllib.request module defines functions and classes ... this function returns a urllib.response.addinfourl object.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Also, the
networkError()andtimeout()methods don’t include the request object in the resultingErrorobject. I have some error handling code that inspects the request, but can’t test the error handlers with the mocks enabled.I had a similar issue, and I’ve fixed it for my tests by adding an extra Interceptor to Axios as a workaround:
This will define a
requestin the main response, so any code that is in theaxios.get().then(...)will have the request defined and the same as config 🎉It will “polyfill” the
.requestif it doesn’t find it with the config, so feel free to put it wherever you want (though I’d recommend to put it in your tests or test setup).