lundi 26 novembre 2018

With Cypress.io, how do you get clock and cookies to work together?

Consider the following test:

it('after a year it requires the user to login again', () => {
  cy.clock();
  cy.visit('/login');

  cy.get('input[name=email]').type(context.email);
  cy.get('input[name=password]').type(`password{enter}`);

  cy.get('[data-testid="notebook-name"]').should('contain', 'My first notebook');

  const minute = 60 * 1000;
  const hour = 60 * minute;
  const day = 2 * hour;
  const year = 365 * day;

  cy.tick(year + day);

  cy.visit('/notebook');

  cy.getCookies().then(cookies => {
    console.log('Cookies: ', cookies);
  });

  cy.getCookies().should('have.length', 0);

  cy.contains('Log in');
});

When running this test I expect my 'token' cookie to have expired, and no longer be returned by cy.getCookies() but that is not the case.

What is the best way to get cy.clock/tick and cypress cookies to work together?

Aucun commentaire:

Enregistrer un commentaire