Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Number matches should not coerce non-numbers to numbers. #617

Open
paperdave opened this issue Jun 15, 2023 · 1 comment
Open

Number matches should not coerce non-numbers to numbers. #617

paperdave opened this issue Jun 15, 2023 · 1 comment

Comments

@paperdave
Copy link

Bug

  • package version: 4.0.0
  • node version: 20.2.0

some number matches don't check if the given value is a number. is this intentional?

The following pass but feel weird because they are strings

expect("").toBeWithin(0, 1); // "" coerces to 0 in >=
expect("4").toBeWithin(0, 10);
expect("1").toBePositive();
expect("-1").toBeNegative();
expect("fsdafdsa").toBeNaN();
expect("2").toBeEven();
expect("3").toBeOdd();
expect("1").toBeInteger();

.toBeNumber() is not affected by this.

@keeganwitt
Copy link
Collaborator

keeganwitt commented Aug 21, 2023

Interesting question. It looks like our number matches have inconsistent behavior regarding this.

Coerces string to Number

  • toBeEven
  • toBeInteger
  • toBeNegative
  • toBeOdd
  • toBePositive
  • toBeWithin

Fails if not a Number

  • toBeFinite
  • toBeNaN
  • toBeNumber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants