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

unbox BigInt primitives in shouldGetter #1349

Merged
merged 2 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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