Jest - mock a single function in a module

Though the requireActual route looked promising, it only worked when I called the mocked function directly in my test, and not when used like in real life.

This answer on StackOverflow ended up helping, as did this discussion on GitHub.

It's definitely not beautiful. Almost makes me miss python mocks.

Here's an example cribbed from that SO:

// myFunctions.ts
import * as thisModule from './module';

export function world() {  
    return 'world';
}

export function hello() {  
    const value = world();
    return `hello ${thisModule.world()}`
}
// myFunctions.spec.ts
import * as theModule from './myFunctions';

describe('function mock test', () => {  
  it('should change that function output', async () => {
    jest.spyOn(theModule, 'world').mockReturnValue('NOT WORLD!')
    ...
  });
});