Skip to content

Commit 5b607a1

Browse files
authored
fix: support inspecting bigints (#1321) (#1383)
1 parent dc858a0 commit 5b607a1

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

chai.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8746,6 +8746,9 @@ function formatPrimitive(ctx, value) {
87468746

87478747
case 'symbol':
87488748
return ctx.stylize(value.toString(), 'symbol');
8749+
8750+
case 'bigint':
8751+
return ctx.stylize(value.toString() + 'n', 'bigint');
87498752
}
87508753
// For some reason typeof null is "object", so special case here.
87518754
if (value === null) {

lib/chai/utils/inspect.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ function formatPrimitive(ctx, value) {
218218

219219
case 'symbol':
220220
return ctx.stylize(value.toString(), 'symbol');
221+
222+
case 'bigint':
223+
return ctx.stylize(value.toString() + 'n', 'bigint');
221224
}
222225
// For some reason typeof null is "object", so special case here.
223226
if (value === null) {

test/utilities.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,16 @@ describe('utilities', function () {
756756
});
757757
});
758758

759+
it('inspect BigInt', function () {
760+
if (typeof BigInt !== 'function') return;
761+
762+
chai.use(function (_chai, _) {
763+
expect(_.inspect(BigInt(0))).to.equal('0n');
764+
expect(_.inspect(BigInt(1234))).to.equal('1234n');
765+
expect(_.inspect(BigInt(-1234))).to.equal('-1234n');
766+
});
767+
});
768+
759769
it('inspect every kind of available TypedArray', function () {
760770
chai.use(function (_chai, _) {
761771
var arr = [1, 2, 3]

0 commit comments

Comments
 (0)