mardi 13 novembre 2018

How to Mock non-default import using Jest

How can I mock a function that is being imported inside the file that contains the function I am testing?

without putting it in the mocks folder.

// FileIWantToTest.js
import { externalFunction } from '../../differentFolder';

export const methodIwantToTest = (x) => { externalFunction(x + 1) }

I need to make sure that externalFunction is called and its called with the correct arguments.

Seems super simple but the documentation doesn't cover how to do this without mocking the module for all the files in the test by putting the mocks in the mocks folder.

Aucun commentaire:

Enregistrer un commentaire