title: In Cypress tests, how do I retry a button click if an expected XHR request does not go out : waitUntil() with click XHR condition??
body: <p>At a very high level, we click a button which commands a building-control point; turns a light on or off. The click is supposed to send a POST request to the server. The issue is sometimes, the button is clicked and the POST request does not go out. The button has no functionality to indicate if it has been clicked (minor enhancement) . </p>
  
  <p>For the time being, I want to work around this using Cypress plug-in <a href="https://www.npmjs.com/package/cypress-wait-until" rel="nofollow noreferrer">waitUntil()</a> .</p>
  
  <pre><code>    // define routes
      cy.server();
      cy.route('POST', '\*\*/pointcommands').as('sendCommand');
  
      // setup checkFunction for cy.waitUntil()
      const waitForPost200 = () =&gt; cy.wait('@sendCommand', {timeout: 10000}).then(xhr =&gt; cy.wrap(xhr).its('status').should('eq', 200));
  
      // setup jQuery for cy.pipe()
      const click = $el =&gt; $el.click();
  
      // click the button
      cy.get('.marengo-ok')
        .should('be.visible')
        .pipe(click);
        // need to pass in a synchronous should() check so that the click is retried. How can we achieve this with waitUntil ?
  
      // wait until checkFunction waitForPost200() returns truthy
      cy.waitUntil( (): any =&gt; waitForPost200(), {
        timeout: 10000,
        interval: 1000,
        errorMsg: 'POST not sent `enter code here`within time limit'
      });
  </code></pre>