I'm trying to test a file which uses zlib which is wrapped in promisify but when the test reaches the line in the code which uses zlib I get a jest timeout error.
: Timeout - Async callback was not invoked within the 30000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 30000 ms timeout specified by jest.setTimeout.Error:
Module file:
import zlib from 'zlib';
import util from 'util';
const zlibGunzip = util.promisify(zlib.gunzip);
async function unzipObjectContent(objectBody): Promise<string> {
const buff = objectBody as Buffer;
try {
const data = await zlibGunzip(buff);
const utf8String = data.toString('utf8');
const parsedJson = JSON.parse(utf8String);
return JSON.stringify(parsedJson);
} catch (error) {
logger.error(`unzipObjectContent -> failed to unzip file ${error}`);
throw error;
}
}
Test File
jest.mock('zlib');
import zlib from 'zlib';
let gunzipMock: jest.SpyInstance;
gunzipMock = jest.spyOn(zlib, 'gunzip');
gunzipMock.mockResolvedValue(JSON.stringify(problemZipContent));
When I debug the test, I see that it reaches the call to await zlibGunzip(buff); but then an error is thrown. It does not reaches the catch block either.
Please advise on how can I test this. Thank you