-
-
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
141902a
commit 879aa26
Showing
5 changed files
with
100 additions
and
1 deletion.
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
62 changes: 62 additions & 0 deletions
62
src/guards/__tests__/is-empty-value.guard.functional.spec.ts
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,62 @@ | ||
import type { Testcase } from '@tests/utils/types' | ||
import * as isEmptyString from '../is-empty-string.guard' | ||
import testSubject from '../is-empty-value.guard' | ||
import * as isNIL from '../is-nil.guard' | ||
|
||
/** | ||
* @file Unit Tests - isEmptyValue | ||
* @module tutils/guards/tests/unit/isEmptyValue | ||
*/ | ||
|
||
describe('unit:guards/isEmptyValue', () => { | ||
const spyIsEmptyString = jest.spyOn(isEmptyString, 'default') | ||
const spyIsNIL = jest.spyOn(isNIL, 'default') | ||
|
||
type Case = Testcase<{ isEmptyString: number; isNIL: number }> & { | ||
state: string | ||
value: any | ||
} | ||
|
||
const cases: Case[] = [ | ||
{ | ||
expected: { isEmptyString: 1, isNIL: 1 }, | ||
state: 'undefined', | ||
value: undefined | ||
}, | ||
{ | ||
expected: { isEmptyString: 1, isNIL: 0 }, | ||
state: 'empty string (trimmed)', | ||
value: '' | ||
}, | ||
{ | ||
expected: { isEmptyString: 1, isNIL: 0 }, | ||
state: 'empty string (untrimmed)', | ||
value: ' ' | ||
}, | ||
{ | ||
expected: { isEmptyString: 1, isNIL: 1 }, | ||
state: 'null', | ||
value: null | ||
}, | ||
{ | ||
expected: { isEmptyString: 1, isNIL: 1 }, | ||
state: 'undefined', | ||
value: undefined | ||
} | ||
] | ||
|
||
for (const { expected, state, value } of cases) { | ||
const times = (num: number) => `${num} time${num === 1 ? '' : 's'}` | ||
const state1 = `isEmptyString ${times(expected.isEmptyString)}` | ||
const state2 = `isNIL ${times(expected.isNIL)}` | ||
|
||
it(`should call ${state1} and ${state2} given ${state}`, () => { | ||
// Act | ||
testSubject(value) | ||
|
||
// Expect | ||
expect(spyIsEmptyString).toBeCalledTimes(expected.isEmptyString) | ||
expect(spyIsNIL).toBeCalledTimes(expected.isNIL) | ||
}) | ||
} | ||
}) |
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,20 @@ | ||
import { EmptyValue } from '@tutils/types' | ||
import isEmptyString from './is-empty-string.guard' | ||
import isNIL from './is-nil.guard' | ||
|
||
/** | ||
* @file Type Guards - isEmptyValue | ||
* @module tutils/guards/isEmptyValue | ||
*/ | ||
|
||
/** | ||
* Checks if `value` is an empty string or `NIL`. | ||
* | ||
* @param {any} [value] - Value to check | ||
* @return {boolean} `true` if `value` is an empty string or `NIL` | ||
*/ | ||
const isEmptyValue = (value?: any): value is EmptyValue => { | ||
return isEmptyString(value) || isNIL(value) | ||
} | ||
|
||
export default isEmptyValue |
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