mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 02:33:54 +03:00
fix(isNotNil): simplify isNotNil
and add testcases (#519)
* Simplify isNotNil and add testcases * fix chore
This commit is contained in:
parent
3409d25a8d
commit
7258981909
@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isBoolean } from './isBoolean';
|
||||
|
||||
describe('isNull', () => {
|
||||
describe('isBoolean', () => {
|
||||
it('returns true if the value is boolean', () => {
|
||||
expect(isBoolean(true)).toBe(true);
|
||||
expect(isBoolean(false)).toBe(true);
|
||||
|
@ -10,6 +10,10 @@ describe('isNotNil', () => {
|
||||
it('returns true if the value is not null nor undefined', () => {
|
||||
expect(isNotNil('')).toBe(true);
|
||||
expect(isNotNil(123)).toBe(true);
|
||||
expect(isNotNil(0)).toBe(true);
|
||||
expect(isNotNil(false)).toBe(true);
|
||||
expect(isNotNil(true)).toBe(true);
|
||||
expect(isNotNil([])).toBe(true);
|
||||
});
|
||||
|
||||
it('can be used with TypeScript as a type predicate', () => {
|
||||
|
@ -15,5 +15,5 @@
|
||||
* // result will be [1, 3]
|
||||
*/
|
||||
export function isNotNil<T>(x: T | null | undefined): x is T {
|
||||
return x !== null && x !== undefined;
|
||||
return x != null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user