question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🐛 Bug Report

BigInt was introduced in Node.js v10.4.0. This feature is expected to be supported by jest. An script to test is added in this issue.

Currently the situation is:

  • BigInt(x) can be used inside Jest but is only supported by the toBeEqual function, but not by toBeGreaterThan, toBeGreaterThanOrEqual, toBeLessThan or toBeLessThanOrEqual. image

  • The format 123n is not supported and causes an error without executing the tests: image

To Reproduce

Use this script. As the format 123n is not supported and break the execution, you can comment the second test to check the other behaviours.

describe('BigInt', () => {
  test('It should accept BigInt("x") way', () => {
    const a = BigInt('123456789012345678901234567890');
    expect(typeof a).toEqual('bigint');
  });
  test('It should accept bigint in 123n format', () => {
    const a = 123456789012345678901234567890n;
    expect(typeof a).toEqual('bigint');
  });
  test('It should allow to do equal comparision', () => {
    const a = BigInt(2);
    expect(a).toEqual(BigInt(2));
  });
  test('It should allow to do greater than comparision', () => {
    const a = BigInt(2);
    expect(a).toBeGreaterThan(1);
  });
  test('It should allow to do greater than or equal comparision', () => {
    const a = BigInt(2);
    expect(a).toBeGreaterThanOrEqual(2);
  });
  test('It should allow to do less than comparision', () => {
    const a = BigInt(2);
    expect(a).toBeLessThan(3);
  });
  test('It should allow to do less than or equal comparision', () => {
    const a = BigInt(2);
    expect(a).toBeLessThanOrEqual(2);
  });
});

Expected behavior

  • Jest should accept bigints in the format 123n.
  • Functions of jest should support bigints.

Link to repl or repo (highly encouraged)

Script is already added to the issue

Run npx envinfo --preset jest

Paste the results here:

> npx envinfo --preset jest
npx: installed 1 in 2.649s

  System:
    OS: Windows 10
    CPU: x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  Binaries:
    Yarn: 1.7.0 - C:\Program Files\node\yarn.CMD
    npm: 6.1.0 - C:\Program Files\node\npm.CMD

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
nickmccurdycommented, Aug 12, 2018

Thanks, I didn’t realize Babel was loaded by default. I think it would be less surprising if it didn’t so Jest behaves like the current Node version as closely as possible. Or perhaps there could be different defaults in the node (off) and jsdom (on) environments.

1reaction
rickhanloniicommented, Dec 1, 2018

+1 on a better error message if you want to submit the PR @MattMorgis

Read more comments on GitHub >

github_iconTop Results From Across the Web

BigInt | Can I use... Support tables for HTML5, CSS3, etc
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >
BigInt - JavaScript - MDN Web Docs
BigInt values represent numeric values which are too large to be ... The operations supported on BigInt values are not constant-time and are ......
Read more >
The Essential Guide To JavaScript's Newest Data Type: BigInt
BigInt is a new data type intended for use when integer values are larger than the range supported by the Number data type....
Read more >
BigInt - The Modern JavaScript Tutorial
BigInt is a special numeric type that provides support for integers of arbitrary length. A bigint is created by appending n to the...
Read more >
Cross Browser Compatibility Score of BigInt - LambdaTest
Browser Support for BigInt · Chrome · Safari · Firefox · IE Internet Explorer · Opera · Edge ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found