Vla*_*159 2 javascript testing automated-tests e2e-testing testcafe
在为网站编写自动化测试时,我在这里得到了以下非常奇怪的错误:代码的重新编写:
68 let selected
69 if( params.includes('-RB') ){
70 let books = Selector('.actions > .link-learn > div').withText('VIEW PRODUCT')
71 const index = books.count
72 selected = books.nth( Math.floor(Math.random() * index) );
73 }
Run Code Online (Sandbox Code Playgroud)
而testcafe在第72行提出以下投诉.
"index" argument is expected to be a number, but it was number.
Run Code Online (Sandbox Code Playgroud)
并且在我的程序中没有以名称编号命名的字符串,变量等.那么这个错误意味着什么,也许这个错误应该抛出一个更加明确的不同信息.
谢谢
你错过await了71号线.一定是
const index = await books.count
Run Code Online (Sandbox Code Playgroud)
没有await,你得到一个Promise包装器而不是实际的count属性.在下一行,Promise NaN在Math.random() * index表达式中变为(不是数字).类型验证失败,因为NaN它不是有效数字,但JavaScript NaN属于该number类型,在错误消息中报告.这就是为什么错误报告有愚蠢的expected to be a number, but it was number消息.
感谢您的反馈并帮助我捕获错误,我已经创建了一个问题:https://github.com/DevExpress/testcafe/issues/2470.我想我们会在下一个版本中修复它.