Search code examples
javascripttypescripttestingtestcafeui-testing

Transform value of Selector


I have a HTML element <div id="the-value">30 000</div> for which the content is calculated.

I need to assert the value of this element to be a valid number (>= 20000), however, the value property returns a string and I cannot assert it using .gte()

This assertion fails with: AssertionError: expected '30 000' to be a number or a date

await t.expect(Selector('#the-value').value).gte(20000);

How can I transform the string to a number before assertion?


Solution

  • As you are using testcafe, you should be able to await the Selector and run the test later on it. So you could do:

    const selector = await Selector('#the-value').value;
    const selectorNumber = parseInt(selector);
    
    await t.expect(selectorNumber).gte(20000);