title: How to mock a const with jest?
body: <p>I've been getting an error while trying to unit test a new method on my service that returns an object that looks like this:</p>
  <pre class="lang-js prettyprint-override"><code>    { 
       requestHeaders: [
        {
          'header1': '...',
          'header2': '...',
          'header3': '...'
        },
        {
          'header1': '...',
          'header2': '...',
          'header3': '...'
      },
      {
          'header1': '...',
          'header2': '...',
          'header3': '...'
      },
     ]
    }
  
  </code></pre>
  <p>My service method:</p>
  <pre class="lang-js prettyprint-override"><code>    const requestObject = this.otherService.getRequestObject(payload);
      const [request] = requestObject.headers.attribute; // This doesn't look good
  
      if(request){
      // Do stuff
      }
  </code></pre>
  <p>When I run <code>npm run test</code></p>
  <pre class="lang-js prettyprint-override"><code>
      TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
  
        32 |     );
      &gt; 33 |     const [request] = requestObject.headers.attribute;
           |                           ^
  
  </code></pre>
  <p>My breaking test:</p>
  <pre class="lang-js prettyprint-override"><code>
    it('should call sendNewRequest() ', async () =&gt; {
  
      jest
        .spyOn(myService, 'isExistingRequest')
        .mockImplementation(() =&gt; Promise.resolve(false));
  
      jest
        .spyOn(myService, 'createNewRequest')
        .mockImplementation();
  
      await myService.handleRequest({});
      expect(myService.createNewProductionOrder).toHaveBeenCalled();
    });
  });
  
  </code></pre>
  <p>I think that my getRequestObject is returning undefined because I'm sending an empty object to my handleRequest method, and getRequestObject is expecting a different thing.
  Now, have in mind that the object I exemplified here is not exactly as the original object is (the original one is much larger and have hundreds of fields), but it is an object with an array of objects.</p>
  <p>How should I approach this since I want to avoid creating manually a requestObject inside my testing file?</p>
  <p>It is worth mentioning that my getRequestObject method is declared like this in an utils file:</p>
  <pre><code>export const objectDtoTransformer = (params) =&gt; {doStuff}
  </code></pre>