Skip to main content

Data Stabilization

Stabilize refreshed dates and generated seeds to avoid flaky tests.

Stabilize data seeds

Data seed generators like Chance or Faker can cause flaky tests. But, happily, each tool provides the ability to use your data.

We advise you to continue using your favorite library and resolve flaky tests with fixed variables only when needed.

Stabilize date and time

When a displayed date is not a primary purpose of a test, it can be convenient to freeze it to a fixed value.

The easier way is to use your test framework feature like this :

/* Cypress command to freeze date to 20 May 2030 */
const now = new Date(2030, 4, 20);
cy.clock(now);

Another way is to use an external library like MockDate to mock the current date.

Hide rebellious components

If none of these methods work, you can hide node DOM from the screenshots with style injection.