-
-
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.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
e7cfedd
commit d64f34c
Showing
4 changed files
with
58 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,12 @@ | ||
/** | ||
* @file Type Tests - isNumber | ||
* @module tutils/guards/tests/unit-d/isNumber | ||
*/ | ||
|
||
import type testSubject from '../is-number' | ||
|
||
describe('unit-d:guards/isNumber', () => { | ||
it('should guard number', () => { | ||
expectTypeOf<typeof testSubject>().guards.toBeNumber() | ||
}) | ||
}) |
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,31 @@ | ||
/** | ||
* @file Unit Tests - isNumber | ||
* @module tutils/guards/tests/unit/isNumber | ||
*/ | ||
|
||
import testSubject from '../is-number' | ||
|
||
describe('unit:guards/isNumber', () => { | ||
it('should return false if value is not a number', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[Number.NaN], | ||
[faker.datatype.array()], | ||
[faker.string.numeric()] | ||
] | ||
|
||
// Act + Expect | ||
cases.forEach(([value]) => expect(testSubject(value)).to.be.false) | ||
}) | ||
|
||
it('should return true if value is a number', () => { | ||
// Arrange | ||
const cases: Parameters<typeof testSubject>[] = [ | ||
[faker.number.float()], | ||
[faker.number.int()] | ||
] | ||
|
||
// Act + Expect | ||
cases.forEach(([value]) => expect(testSubject(value)).to.be.true) | ||
}) | ||
}) |
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,14 @@ | ||
/** | ||
* @file Type Guards - isNumber | ||
* @module tutils/guards/isNumber | ||
*/ | ||
|
||
/** | ||
* Checks if the given `value` is a number. | ||
* | ||
* @param {unknown} value - Value to evaluate | ||
* @return {value is number} `true` if `value` is a number | ||
*/ | ||
const isNumber = (value: unknown): value is number => Number(value) === value | ||
|
||
export default isNumber |