title: Jest: How to spy on an imported function
body: <p>Putting in a small snippet below : </p>
  
  <pre class="lang-js prettyprint-override"><code>import xyz from '../xyz'
  function calculate() {
    return xyz(arg1, arg2).catch((err) =&gt; {
      func1()
      func2()
    })
  }
  export default calculate
  </code></pre>
  
  <p>I'm just trying to assert that xyz is called in jest. How can I do it ? </p>
  
  <p>I tried the following but doesn't work : </p>
  
  <pre class="lang-js prettyprint-override"><code>import * as myModule from '../xyz'
  import calculate from '../../calculate'
  const mock = jest.spyOn(myModule, 'xyz')
  mock.mockReturnValue('mocked value')
  const op = calculate()
  expect(op).toBe('mocked value')
  </code></pre>
  
  <p>This gives me the following error: </p>
  
  <blockquote>
    <p>Cannot spy the xyz property because it is not a function; undefined given instead</p>
  </blockquote>