title: How to mock dependency being used in my React component?
body: <p>I have something akin to the following case:</p>
  
  <pre><code>import { someFunction } from "./utils/function"
  
  class ExampleComponent extends React.Component {
  
    buildPages = () =&gt; {
      return someFunction();
    }
  
    render() {
      const pages = this.buildPages();
  
      return &lt;div className="container"&gt;{pages}&lt;/div&gt;;
    }
  }
  </code></pre>
  
  <p>My code is a lot more complicated than the above, but the above is what it boils down to.</p>
  
  <p>I have the following test:</p>
  
  <pre><code>describe("ExampleComponent", () =&gt; {
    it("should match snapshot", () =&gt; {
      // Somehow mock someFunction being used in the component.
  
      expect(mount(getExampleComponent())).toMatchSnapshot();
    };
  });
  </code></pre>
  
  <p><code>someFunction</code> is an expensive computation, and I basically want it to just be a <code>jest.fn().mockReturnValue(true)</code> when testing. Is there a way to do this? I read up on mocking with jest, but none of them seem to go over this use case. I'm not interested in passing <code>someFunction</code> in as a prop.</p>