Skip to content

BigInts are not properly supported by assertions #1195

@no2chem

Description

@no2chem

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions