title: How to replace global function while doing unit test with jest
body: <p>I'm working on writing unit test for a module. And I really need help for handling the global vars &amp; functions.
  I simply my question as follows:
  Let's say the module I want to test on named 'needTest.js'. It structures as this:</p>
  
  <p><img src="https://i.stack.imgur.com/dvAF1l.png" alt="enter image description here"></p>
  
  <p>Since I only need to test main function in needTest.js, in my test file, I first <code>import main from '../needTest.js'</code>. And my question is: function main does not only need three inputs p1, p2 and p3, it also depends on some global var or functions such as isA, isB, isC. How do I mock those globals in my test file? I want to simply replace the return values of those globals and let my test file ignore what it used to import but only use what I mocked.</p>