Cypress automatically includes moment.js and exposes it as Cypress.moment
.
Use Cypress.moment
to help format or parse dates.
⚠️
Cypress.moment
is deprecated in Cypress 6.1.0 and will be replaced in a future release. Consider migrating to a different datetime formatter. For example, see the recipe Using Day.js instead of Moment.js.
Syntax
Cypress.moment()
Usage
Correct Usage
Cypress.moment()
Incorrect Usage
cy.moment() // Errors, cannot be chained off 'cy'
Examples
Test that the span contains formatted text for today
const todaysDate = Cypress.moment().format('MMM DD, YYYY')
cy.get('span').should('contain', 'Order shipped on: ' + todaysDate)