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
rejectWithValue
is not invoked when testing the createAsyncThunk
action
#4302
Comments
I honestly don't know if we can help you here, this looks more like you're having problem with jest mocks. Could I recommend that you use |
I'll also move the api to rtk query. Perhaps all together will help. |
@phryneas Hi, I replaced axios to rtk query, jest to vitest and use MSW. I got a new problem, that not with
loginThunk.test.tsloginThunk.tsPerhaps you can provide your own vision on how to test code like this. Thank you in advance. |
Instead of Test it like you would actually use it. With a real state. This mocking will get you nowhere. What guarantees that your mock actually behaves like the store? Generally, see https://redux.js.org/usage/writing-tests - under "Example App Code" it even shows how to test a slice. |
First of all, I understand that it's probably not right place to ask. Anyway, I hope you could help me.
I have a
createAsyncThunk
with arejectWithValue
that I want to test with jest.My test file looks next. It crashed on the last line because payload is undefined and as you can see in console.log
rejectedWithValue: false
.How to make it possible to invoke rejectWithValue on a rejected status in jest?
The text was updated successfully, but these errors were encountered: