I am attempting to simulate an axios api call that returns an image buffer as shown below:
<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff e1 00 de 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 06 00 12 01 03 00 01 00 00 00 01 00 ... 12688 more bytes>
The fetch function is implemented separately.
const axios = require('axios');
const logger = require('./logger');
const imageApi = axios.create({
baseURL: 'https://endpoint',
timeout: 5000,
});
const fetchRandomImage = async ({ imageId, width, height }) => {
try {
// Fetch image
const response = await imageApi.get(`/id/${imageId}/${width}/${height}`, {
responseType: 'arraybuffer',
});
return response.data;
} catch (error) {
return null;
}
};
module.exports = fetchRandomImage;
What is the right approach for testing this using jest with mock?