Javascript 使用Cypress.io,您如何让时钟和cookies一起工作?

Javascript 使用Cypress.io,您如何让时钟和cookies一起工作?,javascript,testing,cypress,Javascript,Testing,Cypress,考虑以下测试: 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="noteb

考虑以下测试:

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');
});
运行此测试时,我希望我的“令牌”cookie已过期,并且不再由
cy.getCookies()
返回,但事实并非如此

让cy.clock/tick和cypress Cookie协同工作的最佳方法是什么?

cy.tick()
只调用JS中的计时器(如
setTimeout()
),因此上述方法不起作用。为什么不直接使用
.should('have.property','expiry',expectedExpiry)