I'm writing a test using jest and TS and I want to mock a function from a module, with two different implementations for two tests, although when using import I have an error saying mockImplementation is not a function
BUT, if I import the module with require, everything works. Can someone explain me why?
The snippet below works, but if I change the require to import { execSync } from 'child_process' the error appears
jest.mock('child_process', () => {
return {
execSync: jest.fn(),
};
});
const packageToMock = require('child_process');
packageToMock.execSync.mockImplementation(() => {
return something
});
Also could I have this mock behaviour with spyOn? how?