79500661

Date: 2025-03-11 12:05:33
Score: 2.5
Natty:
Report link

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);
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Looks like a comment (1):
  • Low reputation (1):
Posted by: Studio Wai