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
Update Basic Example in README.MD to include Jest env settings #217
Comments
Hi @npfitz, thanks for raising this, and glad you persisted! I never had to configure that, so not sure why you had to. For example, we have tests using axios. Do we know why axios doesn't work in a jsdom environment? Out of curiosity, I had a quick google, yea jest 26 defaults to jsdom. Apparentlyjest 27 will default to node, whenever that's released. Still worth adding something about jest 26 to the readme if we know why axios needs env node |
Hi @rwalle61, Unfortunately I'm not entirely sure. I would guess that it has something with the fact that axios supports both Node.js as well as working in a browser, both of which offer different mechanisms for creating requests (XMLHTTPRequest vs the http package in node perhaps?). I'd assume that axios looks for things to determine what kind of environment it is in (like the presence of the window object, which jsdom provides) and makes assumptions from that. But that's purely speculation from my part. I do feel it's important to note that axios was still able to make requests and give me the responses, it's just that the response object didn't have the request property populated. Also, I did a little more digging and it looks like for your tests, you are in fact setting jest to work in a node environment, but doing it instead from your jest.config.js |
Ah right, yes as you say, we expect axios responses to come from axios run in the node environment, and we error if fed an axios response from jsdom environment. I never realised this, so thanks for pointing it out! I guess most people are running tests involving axios in a node environment. Yes please, if you'd like, raise a PR adding a note about this in the readme of jest-openapi! Perhaps we should raise an enhancement to support jsdom axios, though from jest 27 onwards the demand for this may be quite low |
OpenAPI version
3
Is your feature request related to a problem? Please describe.
When attempting to run the example provided in the Readme, I had a lot of trouble passing my Axios response to expect and having it work correctly. I was receiving the error:
TypeError: The "url" argument must be of type string. Received undefinedTypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined
This was due to Jest not being run with
--env node
(instead it defaults tojsdom
mode), and axios getting confused about how to include the request object in the response. Without the request in the response object, jest-openapi didn't know how to match up the response to the spec.Describe the solution you'd like
It's entirely possible that I'm an outlier here and either should have known to do this, or my system is configured in a way that caused this issue. But if not, it may be helpful to others to include this hint somewhere. It is worth noting that I wasn't able to find anyone else that had this specific issue.
Additional context
System is a typical windows laptop running Ubuntu 18.04 in WSL2
Are you going to resolve the issue?
I would be happy to submit a PR if the maintainers agree that this is something that should be mentioned in documentation
The text was updated successfully, but these errors were encountered: