Search code examples
javascripttestcafe

Why can't TestCafe expect a expression including both a Selector and a const value?


I have a JS code of TestCafe which could not get the expected result (NaN)

await t.expect(Selector('some-expression').count - someConstVar).eql(1)

However if changed to following, it would work well.

await t.expect(Selector('some-expression').count).eql(1 + someConstVar)

I felt the first one questionable and changed it to the second, although it worked, but just curious, why?


Solution

  • The Selector('some-expression').count expression returns a Promise object, not a number. This is required for correct work of the built-in wait mechanism. Refer the following help topic to learn more about how Selector API works: https://testcafe.io/documentation/402829/guides/basic-guides/element-selectors#how-selectors-work.