How to test existing React Store

52 Views Asked by At

I use Redux powered by "easy peasy". I am trying to test existing React Store. Particularly I need to test the thunk

part of store with thunk that I need to test

...
        clients: [],

...
    loadClients: thunk(async (actions) => {
        try {
            const result = await get(`${baseUrl}/api/clients`);
            actions.parseClientsResponse(result);
        } catch (error) {
            console.log(error);
            actions.displayErrorMessage(error);
        }
    }),

        parseClientsResponse: action((storeState, clients) => {
            storeState.clients = clients;
        }),

Please help me with any ideas how to test it. Assume that the thunk does not take any parameters

1

There are 1 best solutions below

0
On

Eventually, since fetch executes my api call behind the scene, I have solved it using fetchMock

import fetchMock from "jest-fetch-mock";

fetchMock.enableMocks();

    beforeEach(() => {
        fetch.resetMocks();
    });

fetch.mockResponseOnce(JSON.stringify(responseObject));

Thank you @timotgl for help