title: How to test a return value of a mock function in jest
body: <p>I want to test the return value of a mock function in jest.</p>
  
  <p>In following code i want to mock fs module's mkdirSync function</p>
  
  <pre><code>const fs = require("fs");
  
  
  describe("Testing mock fs.mkdirSync", () =&gt; {
      fs.mkdirSync = jest.fn().mockReturnValue(5);
      fs.mkdirSync("./apple");
  
      it("fs.mkdirSync must have been called", () =&gt; {
          expect(fs.mkdirSync).toHaveBeenCalled();
      });
  
      //This test fails with TypeError: Cannot read property '0' of undefined
  
      it("fs.mkdirSync last return value must be 5", () =&gt; {
          expect(fs.mkdirSync.mock.results[0].value).toBe(5);
      });
  
  
  
  });
  </code></pre>
  
  <p>Second test fails with TypeError: Cannot read property '0' of undefined</p>