Can't figure out why I'm encountering this error message:
TypeError: axios.get is not functioning properly
4 |
5 | export const getTotalPayout = async (userId: string) => {
> 6 | const response = await axios.get(`${endpoint}get-total-payout`, { params: userId });
7 | return response.data;
8 | };
9 |
This is my service:
import * as axios from 'axios';
const endpoint = '/api/pool/';
export const getTotalPayout = async (userId: string) => {
const response = await axios.get(`${endpoint}get-total-payout`, { params: userId });
return response.data;
};
This is my jest test:
// import mockAxios from 'axios';
import { getTotalPayout } from './LiquidityPool';
const userId = 'foo';
describe('Pool API', () => {
it('getTotalPayout is called and returns the total_payout for the user', async () => {
// mockAxios.get.mockImplementationOnce(() => {
// Promise.resolve({
// data: {
// total_payout: 100.21,
// },
// });
// });
const response = await getTotalPayout(userId);
console.log('response', response);
});
});
The content of src/__mocks__/axios.js looks like this:
// tslint:disable-next-line:no-empty
const mockNoop = () => new Promise(() => {});
export default {
get: jest.fn(() => Promise.resolve({ data: { total_payout: 100.21 }})),
default: mockNoop,
post: mockNoop,
put: mockNoop,
delete: mockNoop,
patch: mockNoop
};