Reputation: 1677
While writing automated test for a website I got the following very odd error in here are the relovent lines of code:
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 }
and testcafe is making the following complaint at line 72.
"index" argument is expected to be a number, but it was number.
And there are no strings, variables, etc. named with name number in my program. So what does this error mean and maybe this error should throw a different message that is slightly more clear.
thanks
Upvotes: 2
Views: 750
Reputation: 2903
You have missed await
on the line 71. It must be
const index = await books.count
Without await
, you get a Promise wrapper instead of the actual count property. On the next line, the Promise turns into NaN
(not a number) in the Math.random() * index
expression. Type validation fails because NaN
is not a valid number, but in JavaScript NaN
belongs to the number
type, which is reported in error message. That's why error report has the silly expected to be a number, but it was number
message.
Thank your for the feedback and helping me to capture a bug, I've created an issue about it: https://github.com/DevExpress/testcafe/issues/2470. I think we will fix it in the next release.
Upvotes: 5