赛普拉斯 - 错误消息与代码不匹配

Cypress - Error message doesn't match code

如您所见 - 错误消息是关于 cy.contains() 命令的,指向 expect() 代码行。 赛普拉斯没有让我知道真正的错误是什么——测试失败的原因。 我的测试基于下面添加的页面 class。 相关class函数-

class NewAppointment {
    
    selectSeverity(value) {
        cy.get("#severities").select(value)
    }

    chooseAppointmentDate(value) {
        cy.get("[data-handler='selectDay']").contains().click()

    }
}
export default NewAppointment

以及失败的代码部分 -

       cy.get("#severities").should(($severitiesArray) => {
           expect($severitiesArray.get(0)).to.have.property('childElementCount', 6) 
       })
       .then(($severitiesArray) => { let optionVal = new Array()
       optionVal = $severitiesArray.children()
       let optionalValue = optionVal[Math.floor(Math.random() * optionVal.length) + 1]
       addAppointment.selectSeverity(optionalValue.text)
       })

有谁知道为什么会这样and/or如何解决?

已编辑 - 正如所问 - DOM 结构:

还有医生科 -

cy.get("#doctors").should(($doctorSelect) => {
            expect($doctorSelect.get(0)).to.have.property('childElementCount', 7)
       })
       .then(($doctorSelect) => {
        let optionArray = new Array()
        optionArray = $doctorSelect.children()
        let optionalValue = optionArray[Math.floor(Math.random() * optionArray.length) + 1]
        addAppointment.selectDoctor(optionalValue.text)
       })
        addAppointment.chooseAppointmentDate(dateValue)
        cy.get(("#schedule"), { timeout: 30000 }).should(($appointments) => { 
           expect($appointments.children()).to.have.length.of.at.least(1)
        })

cy.contains 需要参数作为字符串。似乎您需要将参数传递给函数 chooseAppointmentDate(value)

中的 ,​​contains()
class NewAppointment {
    
    selectSeverity(value) {
        cy.get("#severities").select(value)
    }

    chooseAppointmentDate(value) {
        cy.get("[data-handler='selectDay']").contains(value).click()

    }
}
export default NewAppointment