0

How I wrote in the title I want to assert exactly integer and later it will be needed to check not specific integer but its range because the number will be changing, but I know the approximate range which I agreed with a team. Below an example out of which I take the required number to check its correctness.

<span _ngcontent-c31="" class="lead-meter__count">
          227,032
</span>

But I check it as a string as you see below:

records = $('div.lead-meter__info > span.lead-meter__count');
await expect(await targeting_page.records.getText()).toEqual('226,032', 'no no')

I want to know is it possible to check it as an integer (though string is being checked very precisely) and further, I want to check for instance:
if this number between 2000 and 3000, it's no matter which number, the main point it matches the range

Alexander Tunick
  • 517
  • 1
  • 6
  • 20

2 Answers2

0
var records = await targeting_page.records.getText();
// replace non-number and non-dot to empty string. 
// then multiple 1 to convert string to number.
var recordsNumber = records.replace(/[^\d.]/g, '') * 1;
var inRang = recordsNumber >= 2000 && recordsNumber < =3000;

expect(inRang).toEqual(true);
yong
  • 13,357
  • 1
  • 16
  • 27
0

This answer on another question helped:

parseFloat(yournumber.replace(/,/g, ''));

basically, it's removing the commas from the string.

Answer of Yong user below also has come in handy

Alexander Tunick
  • 517
  • 1
  • 6
  • 20