Skip to content

Commit

Permalink
add support for bigint in atMost
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Oct 6, 2024
1 parent 36ef35d commit d7bafd4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ Assertion.addMethod('lessThan', assertBelow);
* @name most
* @alias lte
* @alias lessThanOrEqual
* @param {number} n
* @param {unknown} n
* @param {string} msg _optional_
* @namespace BDD
* @public
Expand All @@ -1535,11 +1535,13 @@ function assertMost (n, msg) {
new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
}

const isNumeric = x => ['Number', 'BigInt'].includes(_.type(x))

if (!doLength && (objType === 'date' && nType !== 'date')) {
errorMessage = msgPrefix + 'the argument to most must be a date';
} else if (nType !== 'number' && (doLength || objType === 'number')) {
} else if (!isNumeric(n) && (doLength || isNumeric(obj))) {
errorMessage = msgPrefix + 'the argument to most must be a number';
} else if (!doLength && (objType !== 'date' && objType !== 'number')) {
} else if (!doLength && (objType !== 'date' && !isNumeric(obj))) {
var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
} else {
Expand Down
2 changes: 2 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,8 @@ describe('assert', function () {
it('atMost', function() {
assert.isAtMost(2, 5, '2 should be below 5');
assert.isAtMost(1, 1, '1 should be equal to 1');
assert.isAtMost(2n, 5, '2 should be below 5');
assert.isAtMost(1, 1n, '1 should be equal to 1');

err(function() {
assert.isAtMost(3, 1, 'blah');
Expand Down

0 comments on commit d7bafd4

Please sign in to comment.