knee-cola / jest-mock-axios

Axios mock for Jest
252 stars 42 forks source link

How to mock a response from axios.all? #37

Closed magicspon closed 5 years ago

magicspon commented 5 years ago

hello,

I can see axios.all has been mocked, but I can't see how you handle mocking responses.

Is this possible?

thanks

magicspon commented 5 years ago

Sorted!


expect(mockAxios).toHaveBeenCalledWith('benefit/10')
expect(mockAxios).toHaveBeenCalledWith('selection/10')

expect(mockAxios.all).toHaveBeenCalledTimes(1)
mockAxios.mockResponse({
    data: [
        {
            benefitId: 200
        },
        {
            benefitId: 201
        }
    ]
})
mockAxios.mockResponse({
    data: [
        {
            benefitId: 200
        },
        {
            benefitId: 201
        }
    ]
})

as you were!