I’m trying to mock mssql. I can see by debugging that the mock sql.connect function is being called but it doesn’t seem to be returning after being called and it’s causing the unit test to throw a timeout error and the test fails.
Here is the code that I’m testing:
sql.connect(config.dbConnection, (err) => {
if (err) {
logger.info(err);
} else {
sql.query(`select * from XXX';`, (err, result) => {
if (err) {
logger.info("Error executing call: ", err);
} else {
resolve({ status: httpStatusCodes.StatusCodes.OK, apiResponse: result.recordsets[0][0].ZipCode });
}
});
}
});
Here is the unit test:
it("should call sql.connect", async function () {
const response = await regionalization.regionalizationAPI("02878");
expect(response.status).toEqual(200);
});
Here is the manual mock file:
function connect() {
return jest.fn().mockReturnValue();
}
I have a breakpoint set in the connect function and the debugger stops in the function. No matter what mock function I use the execution isn’t returned back to the code and I keep seeing a timeout error.