мой тест: import configureMockStore from 'redux-mock-store';
import { thunk } from 'redux-thunk';
import { loginThunk, LOGIN_SUCCESS, LOGIN_FAILURE } from '../actions';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

global.fetch = jest.fn();

describe('Login Thunk', () => {
    afterEach(() => {
        fetch.mockClear();
    });

    it('dispatches LOGIN_SUCCESS when login is successful', async () => {
        fetch.mockResolvedValueOnce({
            status: 200,
            json: () => Promise.resolve({ message: 'Login successful' })
        });

        const expectedActions = [{ type: LOGIN_SUCCESS }];
        const store = mockStore({});

        await store.dispatch(loginThunk('validUser', 'validPass'));

        expect(store.getActions()).toEqual(expectedActions);
    });

    it('dispatches LOGIN_FAILURE when login fails', async () => {
        fetch.mockResolvedValueOnce({
            status: 401,
            json: () =>
                Promise.resolve({ message: 'Invalid username or password' })
        });

        const expectedActions = [
            { type: LOGIN_FAILURE, payload: 'Invalid username or password' }
        ];
        const store = mockStore({});

        await store.dispatch(loginThunk('invalidUser', 'invalidPass'));

        expect(store.getActions()).toEqual(expectedActions);
    });

    it('dispatches LOGIN_FAILURE on network error', async () => {
        fetch.mockRejectedValueOnce(new Error('Network error'));

        const expectedActions = [
            { type: LOGIN_FAILURE, payload: 'Network error' }
        ];
        const store = mockStore({});

        await store.dispatch(loginThunk('user', 'pass'));

        expect(store.getActions()).toEqual(expectedActions);
    });
});
actions.js import { fetchWithAuth } from './api.js';

export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_FAILURE = 'LOGIN_FAILURE';
export const FETCH_CARDS_SUCCESS = 'FETCH_CARDS_SUCCESS';
export const FETCH_CARDS_FAILURE = 'FETCH_CARDS_FAILURE';

export const loginSuccess = (username) => ({
    type: LOGIN_SUCCESS,
    payload: username
});

export const loginFailure = (error) => ({
    type: LOGIN_FAILURE,
    payload: error
});


export const loginThunk = (username, password) => {
    return async (dispatch, getState) => {
        try {
            const response = await fetch('http://localhost:5000/login', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({ username, password })
            });

            if (response.status === 200) {
                const data = await response.json();
                localStorage.setItem('accessToken', data.accessToken);
                localStorage.setItem('refreshToken', data.refreshToken);
                dispatch(loginSuccess(data.username));
            } else {
                const { message } = await response.json();
                dispatch(loginFailure(message));
            }
        } catch {
            dispatch(loginFailure('Network error'));
        }
    };
};
export const fetchCardsSuccess = (cards) => ({
    type: FETCH_CARDS_SUCCESS,
    payload: cards
});

export const fetchCardsFailure = (error) => ({
    type: FETCH_CARDS_FAILURE,
    payload: error
});

export const fetchCards = (searchTerm = '') => {
    return async (dispatch) => {
        try {
            const response = await fetchWithAuth(
                `http://localhost:5000/api/cards?search=${encodeURIComponent(searchTerm)}`
            );

            if (!response.ok) {
                throw new Error('Failed to fetch cards');
            }

            const data = await response.json();
            dispatch(fetchCardsSuccess(data));
        } catch (error) {
            console.error(error);
            dispatch(fetchCardsFailure(error.message));
        }
    };
};

export const logout = () => {
    return (dispatch) => {
        localStorage.removeItem('accessToken');
        localStorage.removeItem('refreshToken');
        localStorage.removeItem('username');
        dispatch({ type: 'LOGOUT' });
    };
}; superhell@HOME-PC:~/spring-react$ npm run test

> react-spring@0.1.0 test
> jest

 FAIL  src/Components/Redux/__tests__/actions.test.js
  Login Thunk
    ✕ dispatches LOGIN_SUCCESS when login is successful (6 ms)
    ✓ dispatches LOGIN_FAILURE when login fails
    ✓ dispatches LOGIN_FAILURE on network error

  ● Login Thunk › dispatches LOGIN_SUCCESS when login is successful

    expect(received).toEqual(expected) // deep equality

    - Expected  - 1
    + Received  + 2

      Array [
        Object {
    -     "type": "LOGIN_SUCCESS",
    +     "payload": "Network error",
    +     "type": "LOGIN_FAILURE",
        },
      ]

      24 |         await store.dispatch(loginThunk('validUser', 'validPass'));
      25 |
    > 26 |         expect(store.getActions()).toEqual(expectedActions);
         |                                    ^
      27 |     });
      28 |
      29 |     it('dispatches LOGIN_FAILURE when login fails', async () => {

      at call (src/Components/Redux/__tests__/actions.test.js:26:36)
      at tryCatch (src/Components/Redux/__tests__/actions.test.js:2:1)
      at Generator._invoke (src/Components/Redux/__tests__/actions.test.js:2:1)
      at Generator.next (src/Components/Redux/__tests__/actions.test.js:2:1)
      at asyncGeneratorStep (src/Components/Redux/__tests__/actions.test.js:2:1)
      at _next (src/Components/Redux/__tests__/actions.test.js:2:1)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 2 passed, 3 total
Snapshots:   0 total
Time:        0.42 s, estimated 1 s
Ran all test suites.
superhell@HOME-PC:~/spring-react