Exclusive Clothing Sale On Flipkart

Get up to 50% off on our latest collection.

Shop Now

toMatch() and toBeCloseTo() Jasmin Matcher

 toMatch() and toBeCloseTo() Jasmin Matcher


ToMatch()

 

 

The 'toMatch' matcher should be applied successfully for regular expressions

 

it('Jasmin Matcher - Match function', () =>{

var input = "The dotnetoffice tutorials";

var strPhone = "001-789-56-67";

expect(input).toMatch(/dotnetoffice/);

expect(input).toMatch(/dotnetoffice/i);

expect(input).not.toMatch(/dot1/);

expect(strPhone).toMatch(/\d{3}-\d{3}-\d{2}-\d{2}/);

})

 

toBeCloseTo()

This matcher is used to check whether a number is close to another number, up to a given level of decimal precision.

In our case, we checked whether the expected number was equal to the actual number with a given level of decimal precision.

it('Jasmin Matcher - toBeCloseTo ', () =>{

  var pi = 3.1415926, e = 2.78;

  expect(pi).not.toBeCloseTo(e);

  expect(pi).toBeCloseTo(e,0);

  expect(4.334).toBeCloseTo(4.334);

  expect(4.334).toBeCloseTo(4.3345,1);

  expect(4.334).toBeCloseTo(4.3345,2);

  expect(4.334).not.toBeCloseTo(4.3,2);

  expect(4.223).not.toBeCloseTo(4.22,3);

  expect(4.223).not.toBeCloseTo(4.22,4);

})

 you can learn more on it from below video




Share this

Related Posts

Previous
Next Post »

Exclusive Clothing Sale On Flipkart

Get up to 50% off on our latest collection.

Shop Now