Getting `TypeError: jest.fn is not a function`

You’re using a very old version of Jest that don’t support jest.fn. Jest has significantly improved since then and I highly recommend you to update to the latest version.

Also they don’t do auto mocking now.


The jest object is automatically in scope within every test file, so there's no need to import it explicitly. If you do want to import the jest object directly, you want to import the jest-mock module, not the jest-cli module, via:

// Not necessary inside a Jest test file
import jest from 'jest-mock';

const mock = jest.fn();

It is a bit weird that documentation isn't mentioning that jest is not require('jest'); but require('jest-mock'), the following code should work on v22:

const jest = require('jest-mock');
const spy = jest.fn();