I have problem with reading cookie in my Cypress test
/// <reference types="cypress" />
describe('cookie', () => {
beforeEach(() => {
cy.setCookie('abc', 'def');
});
it('read', () => {
let cookieValue: string;
cy.getCookie('abc').should('exist').then(c => cookieValue = c.value);
cy.wrap(cookieValue).should('not.equal', undefined);
});
});
I have error from last should:
expected undefined to not equal undefined
Edit 1
My aim is to have cookie value synchronically. I managed to have working code:
let cookieValue: string;
it('read', async () => {
cy.wrap(cookieValue).should('equal', undefined);
cookieValue = await new Promise(resolve => cy.getCookie('abc').should('exist').then(c => resolve(c.value)));
cy.wrap(cookieValue).should('not.equal', undefined);
});
but it doesn't look cypress-way. Any other solution?
