Skip to content

Commit c732110

Browse files
test: add guardDefined and update isDefined
1 parent 1379f65 commit c732110

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Function.
2+
import { guardDefined } from '../lib/guard-defined.type';
3+
// Variables.
4+
import { FALSE } from './variables/boolean.const';
5+
import { UNDEFINED } from './variables/undefined.const';
6+
7+
describe(guardDefined.name, () => {
8+
// Defined.
9+
it('is DEFINED', () => expect(guardDefined).toBeDefined());
10+
11+
// Checks ...
12+
describe(`checks`, () => {
13+
it('callback', () => {
14+
guardDefined(UNDEFINED, (result: boolean, value: undefined) => {
15+
expect(result).toBe(FALSE);
16+
expect(value).toBeUndefined();
17+
return result;
18+
});
19+
});
20+
// ... primitives.
21+
describe(`primitive`, () => it(`${UNDEFINED}`, () => expect(guardDefined(UNDEFINED)).toEqual(FALSE)));
22+
});
23+
});

packages/type/src/is/test/is-defined.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ describe(isDefined.name, () => {
6969
it(`'undefined'`, () => {
7070
expect(isDefined(notDefined)).toBe(FALSE);
7171
expect(isDefined(UNDEFINED)).toBe(FALSE);
72-
isDefined(UNDEFINED, (result: boolean) => {
73-
expect(result).toBe(FALSE);
72+
isDefined(UNDEFINED, (result: boolean, value: any) => {
73+
expect(result).toEqual(FALSE);
74+
expect(value).toBeUndefined();
7475
return result;
7576
});
7677
});

0 commit comments

Comments
 (0)