Line
var foo = require('./foo');
evaluated in describe and stored in foo .
Then in the it block you mock it, but this does not apply to the old foo link.
Putting foo after calling mockImplementation will fix the error.
//Test code jest.dontMock('./foo'); jest.dontMock('console'); describe('describe', function() { it('should ', function() { var reference = require('./reference'); reference.result.mockImplementation(function (a, b, c) { return '123' }); var foo = require('./foo'); console.log(foo.getResult()); // undefined console.log(reference.result()); // 123 }); });
source share