In my project, I have a file named lib.ts
:
export const getValue() { return 'original value'; }
export const callGetValue() { return getValue(); }
Additionally, there is a test file called lib.spec.ts
:
import * as lib from './lib';
// ...
it('works', () => {
jest.spyOn(lib, 'getValue').mockImplementation( () => 'new value');
expect(lib.callGetValue()).toBe('new value'); // but it's not returning the expected result!
});
// ...
I am attempting to mock the getValue()
function to make it return 'new value'
. However, for some reason, it is not working as intended. Why could this be happening?