title: Jest - how to check if a function is called by another function
body: <p>I'm using Jest to test some Javascript. In a file, called 'function.js' I have two functions like so:</p>
  <p>functions.js</p>
  <pre><code>const firstFunc = () =&gt; {
    const x = secondFunc()
    return x
  }
  
  const secondFunc = () =&gt; {
    return '5'
  }
  
  module.exports = {
    firstFunc,
    secondFunc
  }
  </code></pre>
  <p>In my Jest test file I have:</p>
  <pre><code>const functions = require('./functions.js')
  
  test('test if secondFunc is called', () =&gt; {
    const mockFunction = jest.fn()
    functions.secondFunc = mockFunction;
    functions.firstFunc()
    expect(mockFunction).toHaveBeenCalled()
  })
  </code></pre>
  <p>I've actually tried many different variations of things like this. I'm unable to get jest.fn() to work I want it to. Overall I'm wanting to be able to see information about secondFunc, such as how many times it was called, what parameters with, etc, but I have to actually call firstFunc. Can anyone help me as I can't seem to figure this out.</p>