How to do it...

We want to test actions. Let's take a look at how we can execute those tests.

Since we've been working with our countries-and-regions example a lot, let's finish by testing (at least some of) its actions and thunks: getCountries() is a good example, and quite similar to getRegions(). It will be good to remember that particular code here, so let's take a look:

export const getCountries = () => async dispatch => {    try {        dispatch(countriesRequest());        const result = await getCountriesAPI();        dispatch(countriesSuccess(result.data));    } catch (e) {        dispatch(countriesFailure());    }};

To begin with, it dispatches an action to mark that a request is being done. Then it waits for the result of a web service call; this will require mocking! ...

Get Modern JavaScript Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.