Generating random Date in cypress

Viewed 114

I am new to cypress and want to generate a random date with the calendar every time it spawns a new date by input or picker.

function getRandomDate() {
    const maxDate = Date.now();
    const timestamp = Math.floor(Math.random() * maxDate);
    return new Date(timestamp);
}
1 Answers

I have modified your code as below and it seems to work.

function getRandomDate() {
  const maxDate = Date.now();
  const timestamp = Math.floor(Math.random() * maxDate);
  return new Date(timestamp).toLocaleDateString('en-GB', { month: 'short', day: '2-digit', year: 'numeric'});
}
Related