I tried using it with a function that was overloaded. For example the list api on googleapis and it was not working.
Eg –
import { google } from 'googleapis';
jest.mock('googleapis', () => ({
google: {
auth: {
OAuth2: jest.fn().mockImplementation(() => ({
setCredentials: jest.fn(),
})),
},
gmail: jest.fn().mockReturnValue({
users: {
messages: {
list: jest.fn(),
get: jest.fn(),
},
},
}),
},
}));
const mockedGmail = google.gmail({ version: 'v1' });
const listApiMock = jest.mocked(mockedGmail.users.messages.list)
Then,if I tried doing:
listApiMock.mockResolvedValue(...)
// it will complain that it doesn’t recognize mockResolvedValue
So had to do the following instead, which breaks type-safety.
const listApiMock = mockedGmail.users.messages.list as jest.Mock;
New contributor
Saadman Khan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.