I want to use an actual API for my react Jest tests. Because the test environment is JSDom, I can't make cross-origin requests. In development this is easily solved by specifying a proxy in the package.json file, however this does not apply to the test suite run through: npm test
.
I know that it is possible to specify a proxy when creating a new JSDom instance using (see docs):
const resourceLoader = new jsdom.ResourceLoader({
proxy: "http://127.0.0.1:9001",
});
Now I can't find a way to use this with my application, which is created using create-react-app (CRA)... So my question is, is there some way to specify a proxy when running Jest through a CRA app?
Thanks!