I got AWS lambda function which I want to unit test it using Jest.
As part of the code I got another file to make http calls, which currently I using as a mock.
During another unit test case I want to have another scenario to check by using a mock.
I tried several ways using Jest to do so, but nothing made my function to return the needed result from the mocked function:
First try:
const api_response_utils = require('api_response_utils').default;
const mock = jest.fn().mockReturnValue(["new return value"])
api_response_utils.get = mock;
Second try:
jest.mock("api_response_utils", () => ({
...jest.requireActual("api_response_utils"),
get: () => {
return ["a", "b"]
},
sendResponse:() => {
return ["a", "b"]
},
}));
Is there any other way to make it ?