I am using Redux Toolkit approach by creating:
- slices with reducer and extra reducers
- thunks with createAsyncThunk API
I Want to understand what is the best way to test with React Testing Library the:
- slices with reducer and extra reducers
- thunks with createAsyncThunk API
A sample is given in the below gist: https://gist.github.com/subhranshudas/8021ec6d205a05680bc9e11f3ef7fb7d
Any feedback is appreciated.
Note: I had asked the same question in Reddit and got the following reply: https://www.reddit.com/r/reduxjs/comments/hvwqc9/reduxtoolkit_unit_testing_strategy/ While I am clear with the "what" from the response, I am looking for a definitive "how" with React Testing Library.
Apologies if it is an obvious question, but I am interested in checking out the definitive ways to do so in React Testing Library (since I am new to it)
Thanks!
createAsyncThunk
. There might be additional convenience added from RTK that makes testing thunks even more concise, but I think you can always falls back on the classic way. See answers for "testing thunks with jest" for example. – Aciculum