How can I assert that the jest mocked module method was called?
E.g. in my .spec.js I have the following jest mocked module:
jest.mock('../../../../services/logs.service.js', () => ({
    log: jest.fn()
}));

Now I would like to assert the log method. I.e. something like this:
//the log was called twice with the text "foo"
expect(log).toHaveBeenCalledWith(2, "foo");

But I can not access the log. I tried putting the log initialization outside the jest mocked module, like so:
const log = jest.fn();
jest.mock('../../../../services/logs.service.js', () => ({
    log
}));

But I got the error:

The module factory of jest.mock() is not allowed to reference any out-of-scope variables.


How can I assert that the jest mocked module method was called?
You can do the following:
JavaScript
import { log } from '../../../../services/logs.service.js';

jest.mock('../../../../services/logs.service.js', () => ({
    log: jest.fn()
}));

expect(log).toHaveBeenCalledWith(2, "foo"); // JavaScript

TypeScript
import { log } from '../../../../services/logs.service.js';

jest.mock('../../../../services/logs.service.js', () => ({
    log: jest.fn()
}));

const mockedLog = log as jest.MockedFunction<typeof log>;

expect(mockedLog).toHaveBeenCalledWith(2, "foo");

