Mh.. It looks like fetchAllWorklogs is not being mocked properly in your test, which is why Jest isn't tracking calls to it.
You are mocking JiraUtils but not fetchAllWorklogs directly. Modify your mock to explicitly mock fetchAllWorklogs:
import * as JiraUtils from "../src/services/JiraUtils";
jest.mock("../src/services/JiraUtils", () => {
const actual = jest.requireActual("../src/services/JiraUtils");
return {
...jest.genMockFromModule("../src/services/JiraUtils"),
getIssuesWithWorklogs: actual.getIssuesWithWorklogs, // Keep this function real
fetchAllWorklogs: jest.fn() // Ensure fetchAllWorklogs is properly mocked
};
});
And since fetchAllWorklogs is called asynchronously inside a then, ensure your test is waiting for it. Add await
in expect() to ensure it has had time to execute:
await new Promise((resolve) => setTimeout(resolve, 100)); // Ensures async execution completes
expect(JiraUtils.fetchAllWorklogs).toHaveBeenCalledWith(result[2].id);
Can you add this and check if it logs anything?
console.log("Mock calls:", JiraUtils.fetchAllWorklogs.mock.calls);