title: Jest mock function's inner variable and change function's behavior?
body: <p>i have little experience with jest as i am trying to change variable in my function as we expect to have error thrown if the function's inner variable(baseUrl) changed to null, my function : </p>
  
  <p><code>buildUrl.js</code>:</p>
  
  <pre class="lang-js prettyprint-override"><code>export function buildUrl(contentId, data, options = {}) {
    let baseUrl = config.has('imgBaseUrl') &amp;&amp; config.get('imgBaseUrl');
    if (!baseUrl) {
      throw new Error('some error');
    }
  }
  </code></pre>
  
  <p>i need to mock the baseUrl to value of null for example and test it</p>
  
  <blockquote>
    <p>buildUrl.test.js</p>
  </blockquote>
  
  <pre><code>import {buildUrl} from "./buildURL";
  ....
   it('throw an error when "baseUrl" is not configured', () =&gt; {
  
     let mockBaseUrl = {baseUrl: null};
     jest.mock('./buildURL', ()=&gt; mockBaseUrl);
     // jest.mock('../../../config/test', ()=&gt;mockImgBaseUrl); // or mock the config to be used by the function?
  
     expect(()=&gt; buildUrl('1.44444', data[0], defaultOptions)).toThrow(
       'some error'
     );
     });
  </code></pre>
  
  <p>another approach using <code>jest.fn()</code> didnt work as expected , maybe i am missing something here...</p>