Skip to content

Commit

Permalink
fix: unbox BigInt primitives in shouldGetter (#1349)
Browse files Browse the repository at this point in the history
* unbox BigInt primitives in shouldGetter

* add tests
  • Loading branch information
dwelle committed Jun 17, 2020
1 parent e54d834 commit b91d0a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/chai/interface/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = function (chai, util) {
if (this instanceof String
|| this instanceof Number
|| this instanceof Boolean
|| typeof Symbol === 'function' && this instanceof Symbol) {
|| typeof Symbol === 'function' && this instanceof Symbol
|| typeof BigInt === 'function' && this instanceof BigInt) {
return new Assertion(this.valueOf(), null, shouldGetter);
}
return new Assertion(this, null, shouldGetter);
Expand Down
21 changes: 21 additions & 0 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,27 @@ describe('should', function() {
}, "expected [] to be arguments but got Array");
});

it('".should" getter should unbox primitive values', function(){
function assert(value) {
const AssertionObject = value.should;
const type = typeof value;
if (AssertionObject.__flags.object !== value) {
throw new Error("value `"+ value.toString() +"` ("+ type +") wasn't unboxed");
}
};

assert("a");
assert(0);
assert(true);
assert(false);
if (typeof Symbol === 'function') {
assert(Symbol("a"));
}
if (typeof BigInt === 'function') {
assert(BigInt(10));
}
});

it('.equal()', function(){
var foo;
should.equal(undefined, foo);
Expand Down

0 comments on commit b91d0a8

Please sign in to comment.