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) #1365

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ module.exports = function (chai, _) {
*
* Add `.not` earlier in the chain to negate `.arguments`. However, it's often
* best to assert which type the target is expected to be, rather than
* asserting that its not an `arguments` object.
* asserting that it’s not an `arguments` object.
*
* expect('foo').to.be.a('string'); // Recommended
* expect('foo').to.not.be.arguments; // Not recommended
Expand Down Expand Up @@ -2297,7 +2297,7 @@ module.exports = function (chai, _) {
* a `descriptor`. The problem is that it creates uncertain expectations by
* asserting that the target either doesn't have a property descriptor with
* the given key `name`, or that it does have a property descriptor with the
* given key `name` but its not deeply equal to the given `descriptor`. It's
* given key `name` but it’s not deeply equal to the given `descriptor`. It's
* often best to identify the exact output that's expected, and then write an
* assertion that only accepts that exact output.
*
Expand Down Expand Up @@ -6028,7 +6028,7 @@ module.exports = function (chai, util) {
* assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {three: 'three'}]);
* assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
*
* @name doesNotHaveAllKeys
* @name hasAnyDeepKeys
* @param {Mixed} object
* @param {Array|Object} keys
* @param {String} message
Expand Down Expand Up @@ -7379,7 +7379,8 @@ module.exports = function (chai, util) {
if (this instanceof String
|| this instanceof Number
|| this instanceof Boolean
|| typeof Symbol === 'function' && this instanceof Symbol) {
|| typeof Symbol === 'function' && this instanceof Symbol
|| typeof BigInt === 'function' && this instanceof BigInt) {
return new Assertion(this.valueOf(), null, shouldGetter);
}
return new Assertion(this, null, shouldGetter);
Expand Down Expand Up @@ -8721,6 +8722,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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