fix: support inspecting bigints (#1321) (#1383)

This commit is contained in:
Mike Frysinger 2021-03-12 11:49:06 -05:00 committed by GitHub
parent dc858a0353
commit 5b607a144e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View file

@ -8746,6 +8746,9 @@ function formatPrimitive(ctx, value) {
case 'symbol':
return ctx.stylize(value.toString(), 'symbol');
case 'bigint':
return ctx.stylize(value.toString() + 'n', 'bigint');
}
// For some reason typeof null is "object", so special case here.
if (value === null) {

View file

@ -218,6 +218,9 @@ function formatPrimitive(ctx, value) {
case 'symbol':
return ctx.stylize(value.toString(), 'symbol');
case 'bigint':
return ctx.stylize(value.toString() + 'n', 'bigint');
}
// For some reason typeof null is "object", so special case here.
if (value === null) {

View file

@ -756,6 +756,16 @@ describe('utilities', function () {
});
});
it('inspect BigInt', function () {
if (typeof BigInt !== 'function') return;
chai.use(function (_chai, _) {
expect(_.inspect(BigInt(0))).to.equal('0n');
expect(_.inspect(BigInt(1234))).to.equal('1234n');
expect(_.inspect(BigInt(-1234))).to.equal('-1234n');
});
});
it('inspect every kind of available TypedArray', function () {
chai.use(function (_chai, _) {
var arr = [1, 2, 3]