W3cubDocs

/Cypress

Cypress.moment

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

© 2020 Cypress.io
Licensed under the MIT License.
https://docs.cypress.io/api/utilities/moment.html