简体   繁体   中英

TestCafe - How to check if the value is greater than or equal in the assertion

I would like to check the value which appears in below selector if it is greater than or equal to 1

<span class="badge badge-pill badge-white"> 0 </span>

(In steps, the value "0" should change into "1" or "2"..)

I defined this selector in common.js

this.pill = Selector('[class*=badge-white]');

and wrote the following assertion:

await t.expect((common.pill).innerText).gte(1);

I received the following error: " AssertionError: expected '1' to be a number or a date'. I do not know how to convert ((common.pill).innerText) to number? I tried sth like this:

await t.expect(Number((common.pill).innerText)).gte(1);

But it does not work. When I check if the value is deep equal eg."3"i write:

await t.expect((common.pill).innerText).eql('3');

And it works. Could anybody help me how to check value greater than or equal? I studied it thoroughly but I can't find a solution https://devexpress.github.io/testcafe/documentation/guides/basic-guides/assert.html :(

I found a solution when created const

const number = await common.pill.innerText;

await t.expect(Number(number)).gte(1);

It works!!!!!!!!!!!!!!!!!!

so my question is why below code did not work

await t.expect(Number((common.pill).innerText)).gte(1);

Your code

await t.expect(Number((common.pill).innerText)).gte(1);

does not work because 'Number' does not expect unresolved promises, so yes, you need to do this as follows:

const number = await common.pill.innerText;
await t.expect(Number(number)).gte(1);

This code

await t.expect((common.pill).innerText).eql('3');

works because 'expect' supports awaiting promises automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM