Решил проблему:
import { logIn } from '@/api/auth/client';
import createApiClientMock from '@/api/createApiClient';
jest.mock('@/api/createApiClient', () => {
const axiosInstance = {
post: jest.fn(),
get: jest.fn(),
};
return jest.fn(() => axiosInstance);
});
const mRequest = createApiClientMock();
describe('Проверка клиента API аутентификации', () => {
it('login success', async () => {
const mResponse = { token: 'token' };
mRequest.post.mockResolvedValueOnce(mResponse);
const actual = await logIn('foo', 'qwerty');
expect(actual).toEqual('token');
expect(mRequest.post).toHaveBeenNthCalledWith(1, 'login/', { username: 'foo', password: 'qwerty' });
});
});