Basic Async Action Creator Test
Explore how to test asynchronous action creators in Redux by returning promises with Jest, mocking axios requests, and using mock stores to verify dispatched actions. Understand the challenges in testing async actions and discover how middleware can simplify async logic testing.
We'll cover the following...
We'll cover the following...
Jest handles async tests by allowing us to return a promise as the test’s result. If a promise is returned, the test runner will wait for the promise to resolve and only then continue to the next test:
it('FETCH_RECIPE', () => {
return store.dispatch(actions.fetchRecipe(100));
});
Since store.dispatch() in this case returns a promise (remember, our fetchRecipe() action creator returns a call to the axios library), ...