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?
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"})