我有 dh.js
const checkDExistsCallback = (err, dResp) => {
if (err)
cbResp.error('failed');
if (dResp.length > 0)
checkDCollectionExists();
else
cbResp.error('Not found.');
};
const checkDCollectionExists = () =>
{
let query = `select sid from tablename where sid = '${objRequestData.dName}' limit 1;`;
genericQueryCall(query, checkDCollCallback);
}
module.exports = {checkDExistsCallback , checkDCollectionExists }
在我的 dh.test.ts
const dhExport = require("./DensityHookReceive");
dhExport.checkDCollectionExists = jest.fn().mockImplementation(() => {});
test('check req dh is exists', () => {
dhExport.checkDExistsCallback(false, '[{}]');
expect(dhExport.checkDCollectionExists).toBeCalled();
});
在 dh.js中, checkDExistsCallback函数在满足 'if' 条件后被调用checkDCollectionExists 。当您查看 dh.test.ts 文件时,我一开始就模拟了 checkDCollectionExists 函数,但是在运行测试时它没有调用模拟函数,而是调用了实际函数。你能帮我弄清楚吗?