title: How to stub a module function with Cypress?
body: <p>I want to create a test with Cypress that has a React component that uses an auth library (<code>@okta/okta-react</code>) with a HOC (<code>withOktaAuth</code>).</p>
  
  <p>My component looks like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>// Welcome.js
  
  import { withOktaAuth } from '@okta/okta-react'
  
  const Welcome = ({authState}) =&gt; {
    return &lt;div&gt;{authState.isAuthenticated ? 'stubbed' : 'not working'}&lt;/div&gt;
  }
  
  export default withOktaAuth(Welcome)
  </code></pre>
  
  <p>I tried to make a test like so:</p>
  
  <pre class="lang-js prettyprint-override"><code>// test.js
  
  import * as OktaReact from '@okta/okta-react'
  
  const withOktaAuthStub = Component =&gt; {
    Component.defaultProps = {
      ...Component.defaultProps,
      authState: {
        isAuthenticated: true,
        isPending: false
      },
      authService: {
        accessToken: '123'
      }
    }
  
    return Component
  }
  
  describe('Test auth', () =&gt; {
    before(() =&gt; {
      cy.stub(OktaReact, 'withOktaAuth').callsFake(withOktaAuthStub)
    })
  
    it('Stubs auth', () =&gt; {
      cy.visit('/welcome')
      cy.contains('stubbed')
    })
  })
  </code></pre>
  
  <p>When I run the test, the component still does not use the stubbed function. Any help is very much appreciated!</p>