title: How to stub a node module in Cypress?
body: <p>I am able to mock modules using jest easily like:</p>
  
  <p><code>import * as PubNub from 'pubnub';</code></p>
  
  <pre class="lang-js prettyprint-override"><code>jest.mock('pubnub', () =&gt;
    jest.fn().mockImplementation(() =&gt; {
      mockPubnubInstance = {
        addListener(options) {
          mockPubnubListener(options);
        },
        publish() {
          return Promise.resolve({});
        },
        subscribe: jest.fn(),
        history(params, callback) {
          return mockHistory(params, callback);
        },
      };
  
      return mockPubnubInstance;
    }),
  );
  </code></pre>
  
  <p>How do I do it in Cypress?</p>
  
  <p><code>cy.stub('pubnub', 'publish').returns(Promise.resolve({}))</code></p>
  
  <p>I tried looking at Cypress stub but it does not seem to work.</p>