title: Jest can't find function in module
body: <p>I have a file with a bunch of helper functions: </p>
  
  <pre><code>// extract repo name from url
  function getRepoName(url) {
    let repoName = url.split("/");
    repoName = repoName[repoName.length - 1];
    repoName = repoName.replace(".git", "");
    repoName = repoName.replace("\n", "");
    return repoName;
  }
  
  // delete patch file
  async function deletePatchFile() {
    return new Promise((resolve, reject) =&gt; {
      exec("rm myPatch.patch", error =&gt; {
        if (error !== null) {
          console.log("exec error deleting patch file: ", error);
          reject(error);
        }
        resolve("successfully removed patch file");
      });
    });
  }
  async function getRepoInfo() {
    return new Promise((resolve, reject) =&gt; {
      exec("git config --get remote.origin.url", (error, stdout) =&gt; {
        if (error !== null) {
          console.log(`exec error: ${error}`);
          reject(error);
        }
  
        const repoUrl = stdout.replace("\n", "");
        resolve(repoUrl);
      });
    });
  }
  
  async function getGitEmail() {
    return new Promise((resolve, reject) =&gt; {
      exec("git config --global user.email", (error, stdout) =&gt; {
        if (error !== null) {
          console.log(`exec error: ${error}`);
          reject(error);
        } else {
          resolve(stdout.replace("\n", ""));
        }
      });
    });
  }
  
  async function getGitUser() {
    return new Promise((resolve, reject) =&gt; {
      exec("git config --global user.name", (error, stdout) =&gt; {
        if (error !== null) {
          console.log(`exec error: ${error}`);
          reject(error);
        } else {
          resolve(stdout.replace("\n", ""));
        }
      });
    });
  </code></pre>
  
  <p>I have a unit test that tests each function. All the tests pass except <code>getRepoName</code>. I get an error: </p>
  
  <blockquote>
    <p>serverScript.getRepoName is not a function. </p>
  </blockquote>
  
  <p>Inside the module, I printed the <code>typeof</code> for the function parameter to confirm that it is indeed a string.</p>
  
  <pre><code>const serverScript = require('../../../scripts/app');
  describe('Test Class', () =&gt; {
      beforeAll(() =&gt; {
      });
    afterAll(() =&gt; {
  
    });
  
    beforeEach(() =&gt; {
    });
  
    afterEach(() =&gt; {
  
    });
    console.log("before tests")
  
  it('getRepoName', () =&gt; {
      const repoName = serverScript.getRepoName("git@github.com:me/repo");
      execpt(repoName.toBe('repo')); 
    });
  
    it('getGitUser', async () =&gt; {
        serverScript.getGitUser = jest.fn().mockReturnValue(Promise.resolve('me'));
    });
  
    it('getGitEmail', async () =&gt; {
        serverScript.getGitEmail = jest.fn().mockReturnValue(Promise.resolve('my@email.com'))
    });
  
    it('getRepoInfo', async () =&gt; {
      serverScript.getRepoInfo = jest.fn().mockReturnValue(Promise.resolve('git@github.com:me/repo'));
    });
  
    it('getBranchName', async () =&gt; {
      serverScript.getBranchName = jest.fn().mockReturnValue(Promise.resolve('test2'));
    });
  
    it('getGitCommits', async () =&gt; {
        serverScript.getGitCommits = jest.fn().mockReturnValue(Promise.resolve(['+ 7c7ca2c4284719c278f66eb61301daaa133a51fb', '+ 60989f60b8addddbbfe8c8ee415812b6783ae00e']))
    });
  
    it('getGitPatchFromLocal', async () =&gt; {
      serverScript.getGitPatchFromLocal = jest.fn().mockReturnValue(Promise.resolve(  "diff --git a/Makefile b/Makefile\
      index 411cc21..fd24145 100644\
      --- a/Makefile\
      +++ b/Makefile\
      .....
      "))
    });
  
    it('getGitPatchFromCommits', async () =&gt; {
      serverScript.getGitPatchFromCommits = jest.fn().mockReturnValue(Promise.resolve("diff --git a/README.rst b/README.rst\
      index 845a0ce..057c4bd 100644\
      --- a/README.rst\
      +++ b/README.rst\
     ...."))
    });
  
    it('deletePatchFile', async () =&gt; {
      serverScript.deletePatchFile = jest.fn().mockReturnValue(Promise.resolve('successfully removed patch file'));
    });
  </code></pre>