Reputation: 37
I'm writing an e2e test and Cypress doesn't wait for the cookie to refresh. When I open the item on the page there is a request for an api, but because the current value of the token in the cookie is out of date, and the new one has not yet come - Cypress crashes due to 401 error.
How can I wait for cookie value to change in Cypress? I tried this, but it didn't work.
cy.waitUntil(() => cy.getCookie(TOKEN_KEY)
.then(old_cookie => cy.getCookie(TOKEN_KEY)
.then(cookie => old_cookie.value !== cookie.value)));
Upvotes: 1
Views: 1672
Reputation: 37
So i solved problem with
let old_cookie='';
cy.getCookie(TOKEN_KEY).then((cookie) => {old_cookie = cookie})
cy.waitUntil(() => cy.getCookie(TOKEN_KEY).then(cookie => old_cookie.value !== cookie.value));
Upvotes: 1