Jest: NaN check

Created on 17 Nov 2017  路  6Comments  路  Source: facebook/jest

Should expect(NaN).toBe(NaN) return true? I guess so, but as you know, NaN is the only value where x !== x, so maybe it's correct to return false here.

Bug good first issue

Most helpful comment

I'm super curious on how many issues will we get in a year from now saying that this is a bug, because ECMAScript says otherwise XD

All 6 comments

It should definitely return true.

Added tags as "Good First Issue"; I think it's a nice task to get familiarized with the expect code. Also, people can workaround now by using expect(Number.isNaN(..)).

@mjesun alternatively people can use jest-extended and have a specific named matcher for this: https://github.com/jest-community/jest-extended#tobenan 馃槃

I'm super curious on how many issues will we get in a year from now saying that this is a bug, because ECMAScript says otherwise XD

Is it easy for someone to change all of the docs for toBe to include the caveat that NaN !== NaN but it's handled?

IMO we should change the helper text from (using ===) to (using Object.is), and then we can expect NaN to be NaN while not lying. That said, as @thymikee said, we're probably going to get a lot of bugs based on that; people won't notice the difference.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ticky picture ticky  路  3Comments

gustavjf picture gustavjf  路  3Comments

kentor picture kentor  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments

nsand picture nsand  路  3Comments