I am currently facing an issue with a simple function that I need to write a test for in order to meet the coverage threshold.
import { lambdaPromise } from '@helpers';
export const main = async event => lambdaPromise(event, findUsers);
The lambdaPromise()
function is supposed to return a Promise. My goal is to mock this function and determine if it was called. Here is my current code:
import { main, findUsers } from '../src/lambdas/user/findUsers';
import { lambdaPromise } from '@helpers';
const mockEvent = {
arguments: {
userDataQuery: {
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfa5a0a7a1aba0aa8fb8a7aebbaab9aabde1aca0a2">[email protected]</a>'
}
}
};
const mockLambdaPromise = jest.fn();
jest.mock('@helpers', () => ({
lambdaPromise: jest.fn().mockImplementation(() => mockLambdaPromise)
}));
describe('findUsers', () => {
it('should have a main function', async () => {
const mockPromise = main(mockEvent);
expect(mockPromise).toBeInstanceOf(Promise);
expect(mockLambdaPromise).toBeCalledWith(mockEvent, findUsers);
});
});
However, the mockLambdaPromise
function never gets called. How can I resolve this issue?