title: Cypress setCookie not working as expected
body: <p>I have added a command <code>getCSRFToken</code> that is used by other commands to get the CSRF token for making requests to my app:</p>
  
  <pre class="lang-js prettyprint-override"><code>Cypress.Commands.add("getCSRFToken", () =&gt; {
    cy.getCookie('XSRF-TOKEN').then((cookie) =&gt; {
      if (!cookie) {
        return cy.request('HEAD', '/')
          .its('headers')
          .then((headers) =&gt; {
            const token = headers['x-xsrf-token'];
            if (!token) {
              throw new Error('XSRF token not found');
            }
  
            return cy.setCookie('XSRF-TOKEN', token)
              .then(() =&gt; token);
          });
      }
  
      return cookie.value;
    });
  });
  </code></pre>
  
  <p>The portion that makes a <code>HEAD</code> request is for usage of this function when no pages have yet been visited in the test, for example when making <code>POST</code> requests to create test data.</p>
  
  <p>AFAICT this looks like it should work to me, however it seems subsequent calls to <code>getCookie</code> doesn't actually retrieve anything:</p>
  
  <p><a href="https://i.stack.imgur.com/pp2CL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pp2CL.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/RdZPG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RdZPG.png" alt="enter image description here"></a></p>
  
  <p>I thought returning the <code>setCookie</code> promise and <code>getCookie</code> promise might make a difference but it does not seem like that is the case.</p>