Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么';在Cypress中,检查输入值是否小于x的正确方法是什么?_Javascript_Html_Testing_Cypress - Fatal编程技术网

Javascript 什么';在Cypress中,检查输入值是否小于x的正确方法是什么?

Javascript 什么';在Cypress中,检查输入值是否小于x的正确方法是什么?,javascript,html,testing,cypress,Javascript,Html,Testing,Cypress,我试图检查an的值是否小于x。用柏树测试的最好方法是什么 示例代码(不起作用): 我知道我可以通过回调来实现这一点,但这似乎有点混乱,特别是考虑到测试输入是否(确切地说)是一件好事: cy.get('.number-input').type('200').should('have.value', '200') Chailt是有效的(请参见),但它需要数值,并且值始终是字符串,因此需要将其转换为数字 此外,Cypress.should('have.value.lt','201')命令是jQuer

我试图检查an的值是否小于x。用柏树测试的最好方法是什么

示例代码(不起作用):

我知道我可以通过回调来实现这一点,但这似乎有点混乱,特别是考虑到测试输入是否(确切地说)是一件好事:

cy.get('.number-input').type('200').should('have.value', '200')

Chai
lt
是有效的(请参见),但它需要数值,并且
值始终是字符串,因此需要将其转换为数字

此外,Cypress
.should('have.value.lt','201')
命令是jQuery和chai运算符的组合,从错误消息来看,这显然是非法的(should参数的语法有点不透明,您只需尝试一下)

所以,这是有效的

cy.get('.number-input').type('200')
  .invoke('val')                         // call the val() method to extract the value
  .then(val => +val)                     // convert it to a number
  .then(val => console.log(typeof val))  // just to check the type
  .should('be.lt', 201)                  // also compare it to a number

漂亮,谢谢!现在一切都变得更有意义了。因此,最短的方法是
cy.get('.number input')。键入('200')。调用('val')。然后(val=>+val)。应该('be.lt',201)
then?正确,我刚刚输入了console.log来显示如何检查命令链中的内容。
cy.get('.number-input').type('200')
  .invoke('val')                         // call the val() method to extract the value
  .then(val => +val)                     // convert it to a number
  .then(val => console.log(typeof val))  // just to check the type
  .should('be.lt', 201)                  // also compare it to a number