Closed
Description
🐛 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.
-
The format 123n is not supported and causes an error without executing the tests:
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