Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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
Reactjs 如何将$el.text()转换为数字类型?_Reactjs_Cypress - Fatal编程技术网

Reactjs 如何将$el.text()转换为数字类型?

Reactjs 如何将$el.text()转换为数字类型?,reactjs,cypress,Reactjs,Cypress,我在cypress中得到这个代码是为了只得到表中的数字 cy.get('.MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root:first-child') .each(($el, $index) => { if ($el.text() !== 'REDHAIR') values.push($el.text()) e

我在cypress中得到这个代码是为了只得到表中的数字

cy.get('.MuiTable-root > .MuiTableBody-root > .MuiTableRow-root  > .MuiTableCell-root:first-child')
   .each(($el, $index) => {
       if ($el.text() !== 'REDHAIR')
          values.push($el.text())
          expect(values.parseInt()).to.be.within(1,3)
但是有一个错误,它说parseInt()在值中没有属性

cy.log有这个结果

log 1
log 2
log 3  

谢谢。

我很肯定,我会的

parseInt(values)

我找到了答案。谢谢你的主意

 if ($el.text() !== REDHAIR') 
    values.push($el.text()) 
    items = values.map(value => parseInt(value)) cy.log('Items', items) 
}).then(() => {
   items.forEach((value) => {
       expect(value).to.be.within(1,3)
   }
}
这将迭代数组中的数字。

values.map(value=>parseInt(value))if($el.text()!==REDHAIR)value.push($el.text())items=values.map(value=>parseInt(value))cy.log('items',items)expect(items).to.be.in(1,3)->错误应为数字或日期无效。if($el.text()!==REDHAIR')value.push($el.text())items=values.map(value=>parseInt(value))cy.log('items',items)expect(items).to.be.in(1,3)->错误应为数字或日期