1

I have a code which is downloading the zip as arraybuffer and subsequently uses admZip to get the files inside. I am trying to unit test a method which calls this method and got stuck around mocking the zip download call.

The code is -

export const downloadZip = async (zipUrl: string): Promise<Buffer>  => {
  const axiosInstance = axios.create({ headers: getHeaders() });
  const body = await axiosInstance.get(zipUrl, {
    responseType: 'arraybuffer'
  });
  
  return body.data
}

Does anyone have any prior experience on this and can help?

akshay22
  • 21
  • 3

1 Answers1

1

This may help.

const mock = new MockAdapter(axiosInstance);
mock.onGet("https://zip_url").reply(200, {data: "zipData"});

await expect(AxiosClient().get("https://zip_url")).tobe({data: "zipData"})
Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71