Вот что я бы сделал:
import {
fetchDetailsRequest, fetchDetailsSuccess, fetchDetailsFailure, fetchDetails,
} from './myModule';
import {
FETCH_USER_REQUEST, FETCH_USER_SUCCESS, FETCH_USER_FAILURE,
} from 'Constants/redux';
import service from 'Api/service';
import { saveError } from 'Api';
jest.mock('Api/service');
jest.mock('Api', () => ({
ROOT_URL: 'url',
saveError: jest.fn(),
}));
describe('my_module', () => {
it('fetchDetailsRequest', () => {
expect(fetchDetailsRequest()).toEqual({ type: FETCH_USER_REQUEST });
});
it('fetchDetailsSuccess', () => {
const res = 'MyRes';
expect(fetchDetailsSuccess(res)).toEqual({ res, type: FETCH_USER_SUCCESS });
});
it('fetchDetailsFailure', () => {
const err = 'MyErr';
expect(fetchDetailsFailure(err)).toEqual({ err, type: FETCH_USER_FAILURE });
});
describe('fetchDetails', () => {
it('success', async () => {
const response = 'response data';
service.get.mockResolvedValue(response);
const dispatch = jest.fn();
await fetchDetails()(dispatch);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, fetchDetailsRequest());
expect(dispatch).toHaveBeenNthCalledWith(2, fetchDetailsSuccess(response));
});
it('failure', async () => {
const error = 'response data';
service.get.mockRejectedValue(error);
const dispatch = jest.fn();
const getState = jest.fn();
const getStateRes = 'stateRes';
getState.mockImplementation(() => getStateRes);
await fetchDetails()(dispatch, getState);
expect(dispatch).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenNthCalledWith(1, fetchDetailsRequest());
expect(dispatch).toHaveBeenNthCalledWith(2, fetchDetailsFailure(error));
expect(saveError).toHaveBeenCalledWith(error, getStateRes);
});
});
});