0

I need a way to check if a spy was called with an approximate value, like it can be done with expect(value).toBeCloseTo(3,2).

Something like this:

expect(spy).toHaveBeenCalledWith("some string", valueToBeCloseTo(3, 2))
scipper
  • 2,944
  • 3
  • 22
  • 45

1 Answers1

0

I think you can use the calls and mostRecent helpers.

const secondArgument = spy.calls.mostRecent().args[1]; // args[0] would be the string
expect(secondArgument).toBeLessThanOrEqual(3);
expect(secondArgument).toBeGreaterThanOrEqual(2);

Check out this link for most recent and this link for toBeLessThanOrEqual and toBeGreaterThanOrEqual.

AliF50
  • 16,947
  • 1
  • 21
  • 37