0

Is there a way to mock a function that is inside of a module like this? I want to mock foo() function in a test without export it. Please could you help?

file.js

function foo(){
  // function 1
  return 'value'
}

function baz(){
  const data = foo()
  return data
}

export default baz

I tried like some

jest.mock('./path', () => ({
  ...jest.requireActual('./path'),
  __esModule: true,
  default: jest.fn(),
  foo(): jest.fn().mockResolvedValue('mockedValue')
}))

and didn't work

Also tried another Google things but it looks like I can only mock what is exported

0 Answers0