title: How to use jest.spyOn function to test a function from another file
body: <p>I am trying to run test case for testing entry point of my web service jest
  I am facing one issue while running the unit test.
  Cannot spy the async function, because it is a property not a function. </p>
  
  <p>I am trying to test if the run function is called in the server.js file</p>
  
  <p>The entry file is somewhat like below.</p>
  
  <pre><code>
      import config from 'config';
  
      export default async function run() {
        try {
         /*
           some code
         */
        } catch (err) {
          process.exit(1);
        }
      }
  
      run();
  
  </code></pre>
  
  <p>And the test file is like below</p>
  
  <pre><code>
      import run from '../server';
      describe('server-test', () =&gt; {
      it('run', async () =&gt; {
          const start = require('../server');
          const spy = jest.spyOn(start, run);
          await run();
          expect(spy).toBeCalled();
        });
      });
  
  </code></pre>
  
  <p>The test should run properly,
  but I am getting below error on running this test </p>
  
  <pre><code>Cannot spy the async function run() {
  
      try {
              /*
               some code.
              */
            } catch (err) {
              process.exit(1);
            }
          } property because it is not a function; undefined given instead
  </code></pre>