-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f27cf72
commit 011f516
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Testcase } from '@tests/utils/types' | ||
import testSubject from '../is-nil.guard' | ||
|
||
/** | ||
* @file Unit Tests - isNIL | ||
* @module tutils/guards/tests/unit/isNIL | ||
*/ | ||
|
||
describe('unit:guards/isNIL', () => { | ||
type Case = Testcase<boolean> & { state: string; value: any } | ||
|
||
const cases: Case[] = [ | ||
{ expected: false, state: 'boolean', value: true }, | ||
{ expected: false, state: 'number', value: 13 }, | ||
{ expected: false, state: 'object', value: { data: 26 } }, | ||
{ expected: false, state: 'string', value: 'string' }, | ||
{ expected: true, state: 'null', value: null }, | ||
{ expected: true, state: 'undefined', value: undefined } | ||
] | ||
|
||
it.each<Case>(cases)('should return $expected given $state', testcase => { | ||
// Arrange | ||
const { expected, value } = testcase | ||
|
||
// Act + Expect | ||
expect(testSubject(value)).toBe(expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NIL } from '@tutils/types' | ||
|
||
/** | ||
* @file Type Guards - isNIL | ||
* @module tutils/guards/isNIL | ||
*/ | ||
|
||
/** | ||
* Checks if `value` is a {@link NIL}. | ||
* | ||
* @param {any} [value] - Value to check | ||
* @return {boolean} `true` if `value` is `null` or `undefined` | ||
*/ | ||
const isNIL = (value?: any): value is NIL => { | ||
return value === null || value === undefined | ||
} | ||
|
||
export default isNIL |