From 5b607a144eba37b0159582ff60d4e55d1a433026 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 12 Mar 2021 11:49:06 -0500 Subject: [PATCH] fix: support inspecting bigints (#1321) (#1383) --- chai.js | 3 +++ lib/chai/utils/inspect.js | 3 +++ test/utilities.js | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/chai.js b/chai.js index 9faa3e50b..e1520f7ac 100644 --- a/chai.js +++ b/chai.js @@ -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) { diff --git a/lib/chai/utils/inspect.js b/lib/chai/utils/inspect.js index b054aebae..fbb9997f8 100644 --- a/lib/chai/utils/inspect.js +++ b/lib/chai/utils/inspect.js @@ -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) { diff --git a/test/utilities.js b/test/utilities.js index a5f3c8f48..0d5b2cf90 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -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]