+
Skip to content

Error with BigInt Serialization in Jest Tests #119

@daniilkananenka

Description

@daniilkananenka

Description

I'm developing smart contracts for TON using Blueprint, which relies on Jest and the @ton/sandbox library for testing. However, I've encountered a significant issue related to Jest's handling of BigInt values. When multiple test files are executed in parallel and a test involving a BigInt fails (e.g., expect(5n).toBe(6n)), the console output does not show the actual assertion error. Instead, it displays the message:

TypeError: Do not know how to serialize a BigInt at stringify (<anonymous>)

This issue is well-documented in Jest's GitHub repository (see issue #11617). Given that BigInt values are frequently used in smart contract testing, this behavior is quite frustrating.

The only workaround currently available is to manually update the Jest version in the Blueprint project to ^30.0.0, but this causes warnings regarding peer dependencies:

npm warn Could not resolve dependency:
npm warn peerOptional jest@"^29.5.0" from @ton/sandbox@0.36.0

I would prefer to see this bug resolved out of the box in the @ton/sandbox package.

Steps to Reproduce

  1. Create a new Blueprint project using the SimpleCounter template.
  2. Duplicate the template test file and rename it to SimpleCounter1.spec.ts.
  3. In the duplicated test, intentionally introduce an error using BigInt. For example:
    it('should reset counter', async () => {
        ...
        expect(5n).toBe(6n)
    });
  4. Run the tests. The console output will lack the reason for the test failure and will only display the message:
    TypeError: Do not know how to serialize a BigInt at stringify (<anonymous>)
    

Environment

Node v22.13.0 (used for reproduction)

Logs or Screenshots

Incorrect behavior (out of the box):

Incorrect behavior

Correct behavior (force bump Jest version to ^30.0.0):

Correct behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载