Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

BigInt support for Number functions #591

Open
mcintyre94 opened this issue Apr 13, 2023 · 0 comments
Open

BigInt support for Number functions #591

mcintyre94 opened this issue Apr 13, 2023 · 0 comments

Comments

@mcintyre94
Copy link

mcintyre94 commented Apr 13, 2023

Feature Request

Description: For each Number related matcher, support BigInt input values

For example this test should pass:

test('passes when value is a number', () => {
  expect(1n).toBeNumber()
});

This matches Jest behaviour: jestjs/jest#8382

test('passes when value is a number', () => {
  expect(1n).toBeGreaterThan(0)
});

Possible solution: Probably need to update each matcher on a case-by-case basis. Initial thoughts for each, might not cover everything:

  • toBeNumber is just a case of updating the typeof check
  • toBeNaN should be able to be fixed by changing from isNaN to Number.isNaN which supports bigint correctly
  • isFinite will probably need to cast its input to Number since Number.isFinite(123n) is false for some reason
  • toBePositive uses isNaN, probably just needs updating to Number.isNaN 🤞
  • toBeNegative seems to work (should add tests though to make sure it keeps working!)
  • toBeEven probably needs to check the type, and use 2n instead of 2 for bigint (can't do bigint % number, or vice versa)
  • toBeOdd same as toBeEven
  • toBeWithin seems to work
  • toBeInteger will probably need to cast its input to Number since Number.isInteger(123n) is false for some reason
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant