admin 管理员组文章数量: 1086019
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.
本文标签: javascriptJest Manual Mocking Not Functioning as ExpectedStack Overflow
版权声明:本文标题:javascript - Jest Manual Mocking Not Functioning as Expected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744086468a2531224.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论