Added toBeNearTo() matcher #298

wants to merge 1 commit into


None yet

6 participants


Matcher for numbers that are close to the actual or 'near enough'.

Accepts an expected result and a precision modifier.

i.e. .toBeNearTo(100, 2) would match 98, 99, 100, 101 & 102

This should perhaps be called toBeCloseTo(), and the existing method of that name might more accurately be called .toBePrecision() or some such but I'll leave that up to you.




What about syntax something like expect(foo).toBeWithin(2).of(100) ?


I'm concerned that being 'near to' doesn't sound precise, how about:

expect(foo).toBeBetween(98, 102);
expect(foo).toBeInRange(98, 102);


A fair point.


@matcarey to be fair this method is all about not being precise.

However, I honestly don't care or know best what the method should be called or which syntax might be used to access such logic. I would though, like to see the functionality implemented so am happy to receive any feedback from repository owners and submit a further commit based on that.

Jasmine member

2.0 rc2 has this matcher, but called toBeCloseTo. Closing, please create a new pull request if this is still an issue for you

@slackersoft slackersoft closed this Oct 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment