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

fix: support inspecting bigints (#1321) #1383

Merged
merged 1 commit into from Mar 12, 2021
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: 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