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

BigInts are not properly supported by assertions #1195

Closed
no2chem opened this issue Sep 14, 2018 · 3 comments
Closed

BigInts are not properly supported by assertions #1195

no2chem opened this issue Sep 14, 2018 · 3 comments

Comments

@no2chem
Copy link

no2chem commented Sep 14, 2018

Although BigInts are a stage 3 proposal, they are supported in Node 10 and V8 6.3. One of the quirks of BigInt is that it's not JSON serializable. When attempting to compare two BigInts, chai uses the JSON, which produces the wrong result.

Here's a minimum example, which works on Node 10 and Chai 4.1.2

> let chai = require('chai')

> chai.should()

> 1n.should.equal(1n)
// ↪AssertionError: expected {} to equal {}

> 1234n.should.equal(123n)
// ↪AssertionError: expected {} to equal {}

I think Chai should check if typeof returns 'bigint'

> typeof 123n
// ↪'bigint'

And use equality to make the comparison in that case (and toString()) instead of JSON serialization.

I'm happy to take a look at this if this is something that others think Chai should support.

@no2chem no2chem changed the title BigInt are not properly supported by assertions BigInts are not properly supported by assertions Sep 14, 2018
@keithamus
Copy link
Member

Hey @no2chem thanks for the issue.

We'll definitely make sure to tackle bigints in the next version of chai! We've added this to our Roadmap https://github.com/chaijs/chai/projects/2! We'll be releasing chai 5 soon, but for now I'll close this issue because it is tracked on our roadmap.

@MicahZoltu
Copy link

I'm still experiencing this with the latest version of Chai. I believe bigint is now stage 4 or final, would really like to see it get supported.

@mattbishop
Copy link

FYI, Mocha just merged support for bigint into their stringify() function: mochajs/mocha#4112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants