🎉 Introducing the Cypress Real World App—a new example app to learn, experiment, tinker, and practice application testing with Cypress.

Learn More

Cypress.moment

Improve this doc

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)

See also