Skip to content

Commit

Permalink
fix: support inspecting bigints (#1321) (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
vapier committed Mar 12, 2021
1 parent dc858a0 commit 5b607a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chai.js
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions lib/chai/utils/inspect.js
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/utilities.js
Expand Up @@ -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]
Expand Down

0 comments on commit 5b607a1

Please sign in to comment.