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
Is there a way to extend a package.json proxy to a testing ENV without ejecting CRA? Or, should I remove the proxy and hard code all API calls? Or should I just mock all the API calls?
Currently using a proxy in my package.json to make API calls to a running local server:
Testing does not involve a server, so it does not make sense to have a proxy.
Since you are using axios, it is easy to specify a base path with a port (using axios.create)
Generally you want to avoid make external calls when testing components as it makes tests brittle. It's better to leave it for the end to end tests.
I'm personally mocking all the api calls with jest. To do that, I have an "api" module acting as layer for my api, and I can mock the functions involved in the current test.
I hope it helps.
@ptoussai Thanks for the suggestions. I didn't know Axios had a create helper, I'll definitely use that. Also, instead of making real API calls, I'll just mock them with by returning fake data.
Is there a way to extend a package.json proxy to a testing ENV without ejecting CRA? Or, should I remove the proxy and hard code all API calls? Or should I just mock all the API calls?
Currently using a proxy in my package.json to make API calls to a running local server:
In one of my components, I'm creating an API call to retrieve a list of subscribers:
While this works fine within the app and in the browser, when running jest+enzyme tests,
/api/subscribers
resolves tohttp://localhost:80
:Subscribers.test.js
The text was updated successfully, but these errors were encountered: