title: How to spy on an imported function using Sinon?
body: <p>Let's say we want to test that a specific function is called by another function using Sinon.</p>
  
  <p><strong>fancyModule.js</strong></p>
  
  <pre><code>export const fancyFunc = () =&gt; {
    console.log('fancyFunc')
  }
  
  export default const fancyDefault = () =&gt; {
    console.log('fancyDefault')
    fancyFunc()
  }
  </code></pre>
  
  <p><strong>fancyModule.test.js</strong></p>
  
  <pre><code>import sinon from 'sinon'
  import fancyDefault, { fancyFunc } from '../fancyModule'
  
  describe('fancyModule', () =&gt; {
    it('calls fancyFunc', () =&gt; {
      const spy = sinon.spy(fancyFunc)
      fancyDefault()
      expect(spy.called).to.be.true
    })
  })
  </code></pre>
  
  <p>When I run this test the actual value is always <strong>false</strong>. Also, the original function <code>fancyFunc()</code> gets invoked (outputs <em>fancyFunc</em>) instead of being mocked.</p>