samedi 1 février 2020

Node Jest mocking a function in a function

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

Aucun commentaire:

Enregistrer un commentaire