admin管理员组文章数量:1278985
I have an input that renders some value. I need to check if the value exists, in other words, at least there should be one characters/ letters in the input field.
I have a test like this in Cypress
cy.get('input').should('be.visible').and(($input) => {
expect($input).to.have.value('')
})
which doesn't work since this test checks if the value is exactly ''
. what I want is that the value should be at least of length 1/ non-empty. Is there a way to do it?
I have an input that renders some value. I need to check if the value exists, in other words, at least there should be one characters/ letters in the input field.
I have a test like this in Cypress
cy.get('input').should('be.visible').and(($input) => {
expect($input).to.have.value('')
})
which doesn't work since this test checks if the value is exactly ''
. what I want is that the value should be at least of length 1/ non-empty. Is there a way to do it?
- try these: stackoverflow./questions/57693281/… – Jayce444 Commented Sep 28, 2020 at 6:41
3 Answers
Reset to default 5if you want to type into the input field
cy.get('input').type("here some value")
.should("have.value","here some value")//checks exactly for that string
or if you want to assert that input not be empty
cy.get('input').should('not.be.empty')
i recmend to check the doc https://docs.cypress.io/api/mands/should.html#Usage
You can do this by matching the value against a regex. You can get more info from the cypress docs.
cy.get('input').should('be.visible').and(($input) => {
const val = $input.val()
expect(val).to.match(/foo/)
})
One of the possible solutions would be to check the value's length
cy.get('input').should('be.visible').and(($input) => {
const val = $input.val()
expect(val.length).toBeGreaterThan(0)
})
本文标签:
版权声明:本文标题:javascript - Cypress: is there a way to assert if the value of an input is not empty or at least with some number of chars - Sta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741268391a2368887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论