|
| 1 | +// Function. |
| 2 | +import { isObjectKeys } from '../lib/is-object-keys.func'; |
| 3 | +// Variables. |
| 4 | +import { ACCESSOR_DESCRIPTOR, DATA_DESCRIPTOR, OBJECT_ONE } from '../../testing/variables/object.const'; |
| 5 | +import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../testing/variables/big-int.const'; |
| 6 | +import { Class, CLASS } from '../../testing/variables/class.const'; |
| 7 | +import { FALSE, TRUE, TRUE_INSTANCE, FALSE_INSTANCE, FALSE_EXPECTATION, TRUE_EXPECTATION } from '../../testing/variables/boolean.const'; |
| 8 | +import { FUNCTION } from '../../testing/variables/function.const'; |
| 9 | +import { NULL } from '../../testing/variables/null.const'; |
| 10 | +import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../testing/variables/number.const'; |
| 11 | +import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../testing/variables/string.const'; |
| 12 | +import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../testing/variables/strict/symbol.const'; |
| 13 | +import { UNDEFINED } from '../../testing/variables/undefined.const'; |
| 14 | + |
| 15 | +describe(isObjectKeys.name , () => { |
| 16 | + // Defined. |
| 17 | + it('is DEFINED', () => expect(isObjectKeys).toBeDefined()); |
| 18 | + |
| 19 | + // Checks ... |
| 20 | + describe(`checks`, () => { |
| 21 | + // ... instance. |
| 22 | + describe(`instance`, () => { |
| 23 | + describe(`CLASS`, () => { |
| 24 | + // number. |
| 25 | + it('has number key', () => { |
| 26 | + expect(isObjectKeys(CLASS, 1030405027)).toBe(TRUE); |
| 27 | + expect(isObjectKeys(CLASS, 5)).toBe(TRUE); |
| 28 | + expect(isObjectKeys(CLASS, [5, 1030405027])).toBe(TRUE); |
| 29 | + }); |
| 30 | + // It doesn't find getter number |
| 31 | + it('has not find getter number', () => expect(isObjectKeys(CLASS, NUMBER)).toBe(FALSE)); |
| 32 | + // string. |
| 33 | + it('has string key', () => { |
| 34 | + expect(isObjectKeys(CLASS, 'surname')).toBe(TRUE); |
| 35 | + expect(isObjectKeys(CLASS, ['firstName', 'surname'])).toBe(TRUE); |
| 36 | + }); |
| 37 | + // symbol. |
| 38 | + it('has not find getter symbol key', () => { |
| 39 | + // It does not find getter symbol key in class |
| 40 | + expect(isObjectKeys(CLASS, SYMBOL_NUMBER)).toBe(FALSE); |
| 41 | + expect(isObjectKeys(CLASS, SYMBOL_STRING)).toBe(FALSE); |
| 42 | + expect(isObjectKeys(CLASS, [SYMBOL_NUMBER, SYMBOL_STRING])).toBe(FALSE); |
| 43 | + }); |
| 44 | + |
| 45 | + // mixed. |
| 46 | + it('has string and number key', () => expect(isObjectKeys(CLASS, [1030405027, 'firstName', 'surname'])).toBe(TRUE)); |
| 47 | + }); |
| 48 | + }); |
| 49 | + // ... function. |
| 50 | + describe(`function`, () => { |
| 51 | + it(`FUNCTION`, () => expect(isObjectKeys(FUNCTION, 'function')).toBe(FALSE)); |
| 52 | + it(`CLASS`, () => expect(isObjectKeys(Class, 'function')).toBe(FALSE)); |
| 53 | + }); |
| 54 | + // ... objects. |
| 55 | + describe('object', () => { |
| 56 | + describe(`descriptor`, () => { |
| 57 | + it(`DATA_DESCRIPTOR`, () => { |
| 58 | + expect(isObjectKeys(DATA_DESCRIPTOR, ['writable', 'value'], ['get', 'set'])).toBe(TRUE); |
| 59 | + expect(isObjectKeys(DATA_DESCRIPTOR, ['writable', 'value'])).toBe(TRUE); |
| 60 | + expect(isObjectKeys(DATA_DESCRIPTOR, 'writable', 'value')).toBe(TRUE); |
| 61 | + expect(isObjectKeys(DATA_DESCRIPTOR, ['get', 'set'])).toBe(FALSE); |
| 62 | + expect(isObjectKeys(DATA_DESCRIPTOR, 'get', 'set')).toBe(FALSE); |
| 63 | + expect(isObjectKeys(DATA_DESCRIPTOR, ['configurable', 'enumerable'], 'writable', 'value')).toBe(TRUE); |
| 64 | + expect(isObjectKeys(DATA_DESCRIPTOR, ['configurable', 'enumerable'], 'value')).toBe(TRUE); |
| 65 | + expect(isObjectKeys(DATA_DESCRIPTOR, ['configurable', 'enumerable'], 'writable')).toBe(TRUE); |
| 66 | + }); |
| 67 | + it(`ACCESSOR_DESCRIPTOR`, () => { |
| 68 | + expect(isObjectKeys(ACCESSOR_DESCRIPTOR, ['writable', 'value'], ['get', 'set'])).toBe(TRUE); |
| 69 | + expect(isObjectKeys(ACCESSOR_DESCRIPTOR, ['configurable', 'enumerable'], 'writable', 'value')).toBe(TRUE); |
| 70 | + expect(isObjectKeys(ACCESSOR_DESCRIPTOR, ['configurable', 'enumerable'], 'get')).toBe(TRUE); |
| 71 | + expect(isObjectKeys(ACCESSOR_DESCRIPTOR, ['configurable', 'enumerable'], 'set')).toBe(TRUE); |
| 72 | + }); |
| 73 | + }); |
| 74 | + describe(`OBJECT_ONE`, () => { |
| 75 | + // number. |
| 76 | + it('has number key', () => { |
| 77 | + expect(isObjectKeys(OBJECT_ONE, 1030405027)).toBe(TRUE); |
| 78 | + expect(isObjectKeys(OBJECT_ONE, 5)).toBe(TRUE); |
| 79 | + expect(isObjectKeys(OBJECT_ONE, NUMBER)).toBe(TRUE); // It doesn't find getter |
| 80 | + expect(isObjectKeys(OBJECT_ONE, [5, 1030405027])).toBe(TRUE); |
| 81 | + }); |
| 82 | + // string. |
| 83 | + it('has string key', () => { |
| 84 | + expect(isObjectKeys(OBJECT_ONE, 'key as string')).toBe(TRUE); |
| 85 | + expect(isObjectKeys(OBJECT_ONE, 'x')).toBe(TRUE); |
| 86 | + expect(isObjectKeys(OBJECT_ONE, STRING)).toBe(TRUE); |
| 87 | + expect(isObjectKeys(OBJECT_ONE, ['key as string', 'x', STRING])).toBe(TRUE); |
| 88 | + }); |
| 89 | + // symbol. |
| 90 | + it('has symbol key', () => { |
| 91 | + expect(isObjectKeys(OBJECT_ONE, SYMBOL_NUMBER)).toBe(TRUE); |
| 92 | + expect(isObjectKeys(OBJECT_ONE, SYMBOL_STRING)).toBe(TRUE); |
| 93 | + expect(isObjectKeys(OBJECT_ONE, [SYMBOL_NUMBER, SYMBOL_STRING])).toBe(TRUE); |
| 94 | + }); |
| 95 | + // mixed. |
| 96 | + it('has mixed key', () => { |
| 97 | + expect(isObjectKeys(OBJECT_ONE, [ |
| 98 | + 'key as string', |
| 99 | + 'x', |
| 100 | + 1030405027, |
| 101 | + 5, |
| 102 | + NUMBER, |
| 103 | + STRING, |
| 104 | + SYMBOL_NUMBER, |
| 105 | + SYMBOL_STRING, |
| 106 | + ])).toBe(TRUE); |
| 107 | + // TRUE, TRUE |
| 108 | + expect(isObjectKeys(OBJECT_ONE, SYMBOL_NUMBER, SYMBOL_STRING)).toBe(TRUE); |
| 109 | + // [TRUE, TRUE] OR [TRUE, TRUE] |
| 110 | + expect(isObjectKeys(OBJECT_ONE, [SYMBOL_NUMBER, STRING], [SYMBOL_STRING, NUMBER])).toBe(TRUE); |
| 111 | + // TRUE OR FALSE |
| 112 | + expect(isObjectKeys(OBJECT_ONE, STRING, 'no property')).toBe(TRUE); |
| 113 | + // FALSE OR TRUE |
| 114 | + expect(isObjectKeys(OBJECT_ONE, 'no property', NUMBER)).toBe(TRUE); |
| 115 | + // [FALSE] OR [FALSE] |
| 116 | + expect(isObjectKeys(OBJECT_ONE, ['no property'], ['no property'])).toBe(FALSE); |
| 117 | + // FALSE OR FALSE |
| 118 | + expect(isObjectKeys(OBJECT_ONE, 'no property one', 'no property two')).toBe(FALSE); |
| 119 | + // [FALSE] OR FALSE |
| 120 | + expect(isObjectKeys(OBJECT_ONE, ['no property one'], 'no property two')).toBe(FALSE); |
| 121 | + // FALSE OR [FALSE] |
| 122 | + expect(isObjectKeys(OBJECT_ONE, 'no property one', ['no property two'])).toBe(FALSE); |
| 123 | + // FALSE OR [FALSE, TRUE] |
| 124 | + expect(isObjectKeys(OBJECT_ONE, 'no property one', ['no property two', STRING])).toBe(FALSE); |
| 125 | + // [FALSE, TRUE] OR FALSE |
| 126 | + expect(isObjectKeys(OBJECT_ONE, ['no property one', STRING], 'no property two')).toBe(FALSE); |
| 127 | + // TRUE OR [FALSE, TRUE] |
| 128 | + expect(isObjectKeys(OBJECT_ONE, NUMBER, ['no property two', STRING])).toBe(TRUE); |
| 129 | + // [FALSE, TRUE] OR TRUE |
| 130 | + expect(isObjectKeys(OBJECT_ONE, ['no property one', STRING], NUMBER)).toBe(TRUE); |
| 131 | + }); |
| 132 | + }); |
| 133 | + }); |
| 134 | + // ... primitives. |
| 135 | + describe(`primitive`, () => { |
| 136 | + // bigint |
| 137 | + describe(`bigint`, () => it(`${BIGINT}`, () => expect(isObjectKeys(BIGINT, 'bigint')).toBe(FALSE))); |
| 138 | + // boolean |
| 139 | + describe(`boolean`, () => { |
| 140 | + it(`${TRUE}`, () => expect(isObjectKeys(TRUE, 'boolean')).toBe(FALSE)); |
| 141 | + it(`${FALSE}`, () => expect(isObjectKeys(FALSE, 'boolean')).toBe(FALSE)); |
| 142 | + }); |
| 143 | + // null |
| 144 | + it(`${NULL}`, () => expect(isObjectKeys(NULL, 'null')).toBe(FALSE)); |
| 145 | + // number |
| 146 | + describe(`number`, () => { |
| 147 | + it(`${NUMBER}`, () => expect(isObjectKeys(NUMBER, 'number')).toBe(FALSE)); |
| 148 | + it(`Number(${NUMBER})`, () => expect(isObjectKeys(NUMBER_INSTANCE, 'number')).toBe(FALSE)); |
| 149 | + }); |
| 150 | + // string |
| 151 | + describe(`string`, () => { |
| 152 | + it(`${STRING}`, () => expect(isObjectKeys(STRING, 'string')).toBe(FALSE)); |
| 153 | + it(`String(${STRING})`, () => expect(isObjectKeys(STRING_INSTANCE, 'string')).toBe(FALSE)); |
| 154 | + }); |
| 155 | + // symbol |
| 156 | + describe(`symbol`, () => { |
| 157 | + it(`Symbol(${NUMBER})`, () => expect(isObjectKeys(SYMBOL_NUMBER, 'symbol')).toBe(FALSE)); |
| 158 | + it(`Symbol(${STRING})`, () => expect(isObjectKeys(SYMBOL_STRING, 'symbol')).toBe(FALSE)); |
| 159 | + }); |
| 160 | + // undefined |
| 161 | + it(`${UNDEFINED}`, () => expect(isObjectKeys(UNDEFINED, 'undefined')).toBe(FALSE)); |
| 162 | + // ... object. |
| 163 | + describe(`object`, () => { |
| 164 | + // BigInt |
| 165 | + describe(`BigInt`, () => it(`${BIGINT_EXPECTATION}`, () => expect(isObjectKeys(BIGINT_INSTANCE, 'bigint')).toBe(FALSE))); |
| 166 | + // Boolean |
| 167 | + describe(`Boolean`, () => { |
| 168 | + it(`${TRUE_EXPECTATION}`, () => expect(isObjectKeys(TRUE_INSTANCE, 'boolean')).toBe(FALSE)); |
| 169 | + it(`${FALSE_EXPECTATION}`, () => expect(isObjectKeys(FALSE_INSTANCE, 'boolean')).toBe(FALSE)); |
| 170 | + }); |
| 171 | + // Number |
| 172 | + describe(`Number`, () => it(`new Number(${NUMBER})`, () => expect(isObjectKeys(NUMBER_NEW_INSTANCE, 'number')).toBe(FALSE))); |
| 173 | + // String |
| 174 | + describe(`String`, () => it(`new String(${STRING})`, () => expect(isObjectKeys(STRING_NEW_INSTANCE, 'string')).toBe(FALSE))); |
| 175 | + }); |
| 176 | + }); |
| 177 | + }); |
| 178 | +}); |
0 commit comments