question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Assert less/greater than or equal to

See original GitHub issue

I was surprised that this doesn’t exist already.

assert.lte(3, 3, '3 is less than or equal to 3');

It might seem like a small shortcut, but things get messy when you’re expecting a number and don’t get one:

console.log(null <= 4);  //=> true
console.log(undefined <= 4);  //=> false

I currently do something along the lines of:

const lte = actual === max || actual && actual < max;
assert.isTrue(lte, '...');

… but this still isn’t perfect, especially if you want '3' < 4 to be an error (comparing a string and a number).

I propose that lte/gte be designed to work strictly with numbers and throw for anything else.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

21reactions
sholladaycommented, Nov 22, 2015

Just discovered that expect / should has this.

expect(3).to.be.at.least(3);
expect(3).to.be.at.most(3);
11reactions
BebeSparkelSparkelcommented, Oct 26, 2017

It would be nice in the docs to include greater/less than so that when searching least and most will pop up

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making assertions - Assertible
Asserts that the response time of the entire request is less than a specified value, 1 second by default. If the HTTP request...
Read more >
Less than or equal (<=) - JavaScript - MDN Web Docs
The less than or equal ( <= ) operator returns true if the left operand is less than or equal to the right...
Read more >
Is there a python assert() method which checks between two ...
You can use assertTrue() for that purpose: self.assertTrue(myInt >= 3 and myInt <= 8). Or, using Python's comparison chaining idiom: self.
Read more >
Python's assert: Debug and Test Your Code Like a Pro
In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development.
Read more >
What are the Different types of Asserts in Postman? - Tools QA
This assert helps us to verify the Response Time of the Request. Below we are verifying that if the Response Time is less...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found