Cypress automatically includes moment.js and exposes it as Cypress.moment
.
Use Cypress.moment
to help format or parse dates.
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)