Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we need assert.isAboveOrEqual and assert.isBelowOrEqual? #580

Closed
RachelSatoyama opened this issue Dec 29, 2015 · 2 comments
Closed

Do we need assert.isAboveOrEqual and assert.isBelowOrEqual? #580

RachelSatoyama opened this issue Dec 29, 2015 · 2 comments

Comments

@RachelSatoyama
Copy link

Here's something that bothers me. We are using assertions in form like assert.equal(a, b), assert.isAbove(a, b), assert.isBelow(a, b) instead of just assert(a == b), assert(a > b), assert(a < b) because in case of failure exact values of variables will be provided in error report, and this is very useful for debug.

The thing is I don't know how this can be achieved for assertions like:
assert.isTrue(a >= b), ``assert.isTrue(a <= b)`

My understanding is that assert.isTrue(a >= b) is equivalent of assert.isAbove(a, b) or assert.equal(a, b), but there's no such thing like or in chai assertions. I can use assert.operator, but it looks like it involves eval under the hood - and I don't like it per se.

So, my question is - what is the best way to assert "above-or-equal" and "below-or-equal" type of assertions?

Is it 100% safe to use assert.operator (I doubt to be honest)? Or may be it would be more beneficial to have assert.isAboveOrEqual / assert.isBelowOrEqual? Or, may be even more radical approach makes sense, like introducing sort of assert.any conjuction?

PS: I'm pretty old school in questions regarding how and where this kind of stuff should be discussed. If it is something that is more appropriate for, I don't know, gitter, slack etc. - I apologize.

@keithamus
Copy link
Member

Hey @RachelSatoyama thanks for the questions!

Firstly, I'm going to quickly talk about assert.operator; it doesn't use eval! Since version 2.1.2, (see #395, #386 for history), it's actually just a big switch - because we know there are a limited number of operators you could use, so we just switch on them all. In fact the whole Chai codebase does not contain a single eval (or new Function) 🎉.

Secondly, and more to your point: we have some asserts for >= and <=; assert.isAtLeast (for >=) and assert.isAtMost (for <=). These were added in Chai 3.3.0 so as long as you're using that you should be fine. Sadly, our site's documentation is really out of date right now so it's no surprise you couldn't find them, we're working on it (see chaijs/chaijs.github.io#74 for more if you want).

I'll close this, because we have isAtLeast/isAtMost which should be what you're after, and although our docs are definitely the bit where we failed you, we have an issue for tracking that (chaijs/chaijs.github.io#74). In future, you're totally welcome to keep posting issues on here if you run into any, although you might get a faster response from our slack or gitter channels, but use whatever makes you feel comfortable 😄

@RachelSatoyama
Copy link
Author

Thanks @keithamus, now everything is clear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants