Javascript – jest.spyOn() works on imported module but fails on imported function of the same module
// my-func.test.js import { jest } from '@jest/globals'; import { myFunc } from './my-func.js'; import fs from 'node:fs'; const mock = jest.fn().mockReturnValue({isDirectory: () => true}); jest.spyOn(fs, 'statSync').mockImplementation(mock); it('should work', () => { expect(myFunc('/test')).toBeTruthy(); expect(mock).toHaveBeenCalled(); }); The test passes with this…