-
Notifications
You must be signed in to change notification settings - Fork 42
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
jest-mock-axios incompatible with CRA 4 / resetMocks: true #63
Comments
Hi, thanks for reporting - I was able to reproduce this with the latest version of create-react-app / react-scripts. It looks like this is related to
in your |
Thanks for looking into this and responding so quickly with a workaround! 🎉 |
I also ran into this issue after the CRA 4.0 upgrade, and I can confirm that the |
Hmm, the |
Hi, there are several upstream issues for the @alexburlton-sonocent I created a repro-repo using the example code you provided at kingjan1999/jest-mock-axios-cra-repo. Can you try if this works for you and look for differences between this repo and your project? |
Sorry for going AWOL, the create-react-app upgrade dropped off our radar for a bit so I've not been looking at this for a while. Dug into this a bit more today and have concluded that it's our use of react-app-rewired which is breaking the workaround. If I change our test command to go via vanilla So now I need to figure out if we can drop |
Not sure if related, but I am getting const setAuthConfig = (config) => {
const token = localStorage.getItem('access');
if (token) { config.headers.Authorization = `Bearer ${token}`; }
return config;
};
Setting |
@doutatsu Can you post a more complete example that shows how you invoke |
@doutatsu did you ever resolve this issue? I'm facing the exact same problem |
I don't use Jest anymore, I've switched to Vitest |
Hi!
We're using this library in a project built with Create React App, and have followed the async / await testing pattern outlined in #28.
I'm trying to upgrade us to CRA 4, but doing so is breaking all of these tests with
Error: No request to respond to!
. Bumping major CRA version bumps a load of sub-dependencies, so guessing one of these is the actual cause (jest seems most likely) - I'm happy to check other package versions before/after the upgrade if there are any in particular you think will be relevant!We were using version
2.3.0
of this library, but can also reproduce the issue on the latest version (4.2.1
). I've put together a SRE of three files to demonstrate what's happening.Our axios instance, defined in
axiosInstance.ts
A fake API to test in
sreApi.ts
The test that fails after the upgrade, but passes before in
sreApi.test.ts
In the above example, the
mockResponse
line blows up with:Interestingly, reordering the test like this still fails but does pass the call assertion, so
mockAxios.post
is definitely still being called:Versions that work:
jest
:24.9.0
react-scripts
:3.4.4
axios
:0.18.1
jest-mock-axios
:4.2.1
Versions that don't work (after upgrade):
jest
:26.6.0
react-scripts
:4.0.1
axios
:0.18.1
jest-mock-axios
:4.2.1
The text was updated successfully, but these errors were encountered: