Fix NaN detection in .is() (#159)

This commit is contained in:
Filip Skokan 2022-06-09 19:05:31 +02:00 committed by GitHub
parent 65ea91297e
commit c408f5a268
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -51,6 +51,7 @@ const objectTypeNames = [
'FormData', 'FormData',
'URLSearchParams', 'URLSearchParams',
'HTMLElement', 'HTMLElement',
'NaN',
...typedArrayTypeNames ...typedArrayTypeNames
] as const; ] as const;
@ -111,7 +112,7 @@ function is(value: unknown): TypeName {
case 'string': case 'string':
return 'string'; return 'string';
case 'number': case 'number':
return 'number'; return Number.isNaN(value) ? 'NaN' : 'number';
case 'boolean': case 'boolean':
return 'boolean'; return 'boolean';
case 'function': case 'function':

View file

@ -454,7 +454,7 @@ const types = new Map<string, Test>([
NaN, NaN,
Number.NaN Number.NaN
], ],
typename: 'number', typename: 'NaN',
typeDescription: AssertionTypeDescription.nan typeDescription: AssertionTypeDescription.nan
}], }],
['nullOrUndefined', { ['nullOrUndefined', {