0

柏树时刻不起作用。将日期、月份和年份添加到当前或选定日期的任何其他解决方案。

import * as moment from 'moment'

class TicketPage{
   constructor(){}
    visit(){
        cy.visit('');
    }
    clickDate(){
        const field =cy.get('#content > section.container > div > div > div.col-lg-5.mb-4.mb-lg-0 > form > div:nth-child(3) > div > input')
        field.click()
        const targetDate = Cypress.moment()
         .add(1, 'year')
         .add(1, 'month')
         .add(1, 'day')
         .format('MM/DD/YYYY')
        field.type(targetDate);
        field.invoke('attr', 'placeholder').should('contain', 'Select Date')
        return this
    }
 }
4

1 回答 1

1

Cypress 推荐dayjs作为 moment 的替代品。

语法看起来几乎相同:

import dayjs from 'dayjs'

const targetDate = dayjs()
  .add(1, 'year')
  .add(1, 'month')
  .add(1, 'day')
  .format('MM/DD/YYYY')
于 2021-07-29T06:54:31.700 回答