i am learning unit testing in vue with typescript and i want to test this function
const getCLients =async (): Promise<Client[]> => {
const {data} = await clientsApi.get('/clients')
return data
}
But i got an error due to the clientsApi. My clients api is aun axios instance and looks like this:
import axios from 'axios'
const clientsApi = axios.create({
baseURL:import.meta.env.VITE_API_URL
})
export default clientsApi
my error is this:
TypeError: Cannot read properties of undefined (reading 'get') ❯ getCLients ../src/clients/composables/useClients.ts:14:41
14| const {data} = await clientsApi.get('/clients')
In my tests i have done the axios mock:
vi.mock('axios')
const mockedAxios = axios as jest.Mocked<typeof axios>;
mockedAxios.get.mockResolvedValue({
data: mockClients,
})
I suposed that i had to make a mock of the axios.create but i have tried with a lot of ways but i always got the same typoe error. I need your help, how could you solve this?