1

I am trying to test createAsyncThunk actions the same way I test createAction but it fails and nothing changes in the reducers.

I have made a small app to simulate the cases I made createAsyncThunk and made some tests for it but unfortunately, any tests related to createAsyncThunk fail.

here's the Repo link ReduxToolkitTesting

Lib used this is Repo

  • Redux Toolkit (For Sure :D)
  • React-navigation (Assuming this is the most used navigation lib)
  • UI Kitten (Theming and Components ready to use)

Store consists of 2 reducers

  • Gallery:

    • Set loading indicator to true till fetch is done
    • Fetch random pic from public API and set loading indicator to false
    • If an error happened it reject with an error message and set loading indicator to false
    • Reset Picture to default state
  • Theme

    • Toggle to switch between dark or light theme (also createAsyncThunk cuz I need access to getState), I know I can just pass the value but I need it to be like this just for testing experiment.

I made tests for both reducers and for the Home page which contain buttons to simulate all these behaviors too,

also made render function as mentioned in Redux Doc but and just add the store in the return from the render function with Jest.spyOn on all the functions in case of want to check specific action calls.

right now any test related to createAsyncThunk is failing and can't find any way to fix it or to test some functionalities in another way.

PS. This is might be a lot to ask but I won't remove this Repo and it would be huge if we could contribute to it to be something like a live example on how to test Redux Toolkit and add more scenarios with its a test for advanced testing would be awesome too.

Thanks in advance.

Lin Du
  • 88,126
  • 95
  • 281
  • 483
Snowflake
  • 191
  • 1
  • 2
  • 13
  • Can you provide a [mvce](https://stackoverflow.com/help/minimal-reproducible-example) to explain your question instead of a whole project link? – Lin Du Dec 28 '21 at 02:06
  • @slideshowp2 Actually this project is the example, I made to demonstrate the problem I am facing. – Snowflake Dec 28 '21 at 07:31

0 Answers0