I am Testing a method like such:
test('Test', async () => {
const result = await methodBeingTested(someData);
})
})
Then the method I am testing looks something like this:
import { insertData } from '../util/api';
export async function methodBeingTested(someData: any) {
const data = await insertData(dateIdsomeData)
//Do Some other stuff
return data
}
I would like to mock the data insertData
method returns just so it doesn't do the axios request or the insert into mongo / sql.
How am I able to do this with Jest? I am mainly just wanting to test the functionality of the other stuff going on in the methodBeingTested
.
Thanks
Do this:
jest.mock('../util/api', () => ({
insertData: () => Promise.resolve(mockResult) // put here some result
}));
// your tests
Just make sure that your path is correct.