|
| 1 | +// Function. |
| 2 | +import { guardPrimitive } from '../lib/guard-primitive.func'; |
| 3 | +// Variables. |
| 4 | +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const'; |
| 5 | +import { FALSE, TRUE, TRUE_INSTANCE, FALSE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from './variables/boolean.const'; |
| 6 | +import { NULL } from './variables/null.const'; |
| 7 | +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from './variables/number.const'; |
| 8 | +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from './variables/string.const'; |
| 9 | +import { SYMBOL_NUMBER, SYMBOL_STRING } from './variables/symbol.const'; |
| 10 | +import { UNDEFINED } from './variables/undefined.const'; |
| 11 | + |
| 12 | +describe(guardPrimitive.name, () => { |
| 13 | + // Defined. |
| 14 | + it('is DEFINED', () => expect(guardPrimitive).toBeDefined()); |
| 15 | + |
| 16 | + // Checks ... |
| 17 | + describe(`checks`, () => { |
| 18 | + it('callback', () => { |
| 19 | + guardPrimitive<string>(STRING, 'string' , (result: boolean, value: string) => { |
| 20 | + expect(result).toBe(TRUE); |
| 21 | + expect(value).toEqual(STRING); |
| 22 | + return result; |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + // ... primitives. |
| 27 | + describe(`primitive`, () => { |
| 28 | + // bigint |
| 29 | + describe(`bigint`, () => { |
| 30 | + it(`${BIGINT}`, () => expect(guardPrimitive(BIGINT, 'bigint')).toBe(TRUE)); |
| 31 | + it(`${BIGINT_EXPECTATION}`, () => expect(guardPrimitive(BIGINT_INSTANCE, 'bigint')).toBe(TRUE)); |
| 32 | + }); |
| 33 | + |
| 34 | + // boolean |
| 35 | + describe(`boolean`, () => { |
| 36 | + it(`${TRUE}`, () => expect(guardPrimitive(TRUE, 'boolean')).toBe(TRUE)); |
| 37 | + it(`${FALSE}`, () => expect(guardPrimitive(FALSE, 'boolean')).toBe(TRUE)); |
| 38 | + // it(`${TRUE_EXPECTATION}`, () => expect(guardPrimitive(TRUE_INSTANCE, 'boolean')).toBe(TRUE)); |
| 39 | + // it(`${FALSE_EXPECTATION}`, () => expect(guardPrimitive(FALSE_INSTANCE, 'boolean')).toBe(TRUE)); |
| 40 | + }); |
| 41 | + |
| 42 | + // null |
| 43 | + it(`${NULL}`, () => expect(guardPrimitive(NULL, 'null')).toBe(TRUE)); |
| 44 | + |
| 45 | + // number |
| 46 | + describe(`number`, () => { |
| 47 | + it(`${NUMBER}`, () => expect(guardPrimitive(NUMBER, 'number')).toBe(TRUE)); |
| 48 | + // it(`Number(${NUMBER})`, () => expect(guardPrimitive(NUMBER_INSTANCE, 'number')).toBe(TRUE)); |
| 49 | + // it(`new Number(${NUMBER})`, () => expect(guardPrimitive(NUMBER_NEW_INSTANCE, 'number')).toBe(TRUE)); |
| 50 | + }); |
| 51 | + |
| 52 | + // string |
| 53 | + describe(`string`, () => { |
| 54 | + it(`${STRING}`, () => expect(guardPrimitive(STRING, 'string')).toBe(TRUE)); |
| 55 | + // it(`String(${STRING})`, () => expect(guardPrimitive(STRING_INSTANCE, 'string')).toBe(TRUE)); |
| 56 | + // it(`new String(${STRING})`, () => expect(guardPrimitive(STRING_NEW_INSTANCE, 'string')).toBe(TRUE)); |
| 57 | + }); |
| 58 | + |
| 59 | + // symbol |
| 60 | + describe(`symbol`, () => { |
| 61 | + it(`Symbol(${NUMBER})`, () => expect(guardPrimitive(SYMBOL_NUMBER, 'symbol')).toBe(TRUE)); |
| 62 | + it(`Symbol(${STRING})`, () => expect(guardPrimitive(SYMBOL_STRING, 'symbol')).toBe(TRUE)); |
| 63 | + }); |
| 64 | + |
| 65 | + // undefined |
| 66 | + it(`${UNDEFINED}`, () => expect(guardPrimitive(UNDEFINED, 'undefined')).toBe(TRUE)); |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments