Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5631b4a
fix: correct typo in CI workflow for test command
MForofontov Feb 8, 2025
5331b20
test: add additional test cases for applyDefaults function to handle …
MForofontov Feb 8, 2025
dad3ad0
test: update flipObject test cases to cover additional scenarios and …
MForofontov Feb 8, 2025
00455d9
test: enhance getDeepEqualityHash test cases to cover various data ty…
MForofontov Feb 8, 2025
24412b7
test: update flipObject test cases to handle nested objects and impro…
MForofontov Feb 8, 2025
7984f5a
test: update flattenObject test cases to handle various data types an…
MForofontov Feb 8, 2025
60f4901
test: enhance deepMerge and flipObject test cases to cover various da…
MForofontov Feb 8, 2025
1bbdb61
test: add cases to flattenObject for nested arrays and improve non-ob…
MForofontov Feb 8, 2025
d867c41
test: add cases to deepMerge for handling symbols and improve non-obj…
MForofontov Feb 8, 2025
7b33f4b
test: enhance deepFreeze test cases to cover various data types and i…
MForofontov Feb 8, 2025
27a12a2
test: enhance deepEqual test cases to improve coverage for various da…
MForofontov Feb 8, 2025
78b2a73
test: enhance hasKey test cases to cover nested objects, arrays, and …
MForofontov Feb 8, 2025
586d454
test: enhance getNestedValue test cases to cover various data types a…
MForofontov Feb 8, 2025
15bdbc8
test: enhance getObjectDifference test cases to cover various data ty…
MForofontov Feb 8, 2025
b8d42d1
test: update hasKey test cases to remove TypeScript type assertions a…
MForofontov Feb 8, 2025
bc850b2
test: enhance isEmptyObject test cases for clarity and coverage of va…
MForofontov Feb 8, 2025
7026a9a
test: remove isEmptyObject tests and consolidate functionality into i…
MForofontov Feb 8, 2025
22d7ac0
test: enhance keysToCamelCase tests for clarity and coverage of vario…
MForofontov Feb 8, 2025
e1ed062
test: enhance keysToSnakeCase test cases for clarity and coverage of …
MForofontov Feb 8, 2025
9e2ec05
test: enhance keysToCamelCase and keysToSnakeCase tests for handling …
MForofontov Feb 8, 2025
e37dd99
test: enhance objectToQueryString tests for clarity and coverage of v…
MForofontov Feb 8, 2025
ce09d8e
test: enhance omitKeys tests for clarity and coverage of various scen…
MForofontov Feb 8, 2025
c770362
test: enhance objectToQueryString and omitKeys tests for handling emp…
MForofontov Feb 8, 2025
0b326bf
test: enhance pickKeys tests for clarity and coverage of various scen…
MForofontov Feb 8, 2025
17b8f15
test: enhance queryStringToObject tests for clarity and coverage of v…
MForofontov Feb 8, 2025
9247082
test: enhance removeEmptyValues tests for clarity and coverage of var…
MForofontov Feb 8, 2025
0f91398
test: enhance setNestedValue tests for clarity and coverage of variou…
MForofontov Feb 8, 2025
4bd562d
refactor: improve documentation and enhance tests for object functions
MForofontov Feb 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: npm install

- name: Run tests
run: npm test:github"
run: npm test:github

- name: Upload Allure report
if: ${{ github.event.inputs.upload_report == 'true' }}
Expand Down
58 changes: 38 additions & 20 deletions functionsUnittests/objectFunctions/applyDefaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,71 @@ describe('applyDefaults', () => {
expect(result).toEqual(expected);
});

// Test case 4: Handle non-object input for the first parameter (number)
it('4. should throw a TypeError if the first input is a number', () => {
// Test case 4: Handle empty defaults
it('4. should return the input object if defaults are empty', () => {
const obj = { a: 1, b: 2 };
const defaults = {};
const result = applyDefaults(obj, defaults);
const expected = { a: 1, b: 2 };
expect(result).toEqual(expected);
});

// Test case 5: Handle both input objects being empty
it('5. should return an empty object if both inputs are empty', () => {
const obj = {};
const defaults = {};
const result = applyDefaults(obj, defaults);
const expected = {};
expect(result).toEqual(expected);
});

// Test case 6: Handle non-object input for the first parameter (number)
it('6. should throw a TypeError if the first input is a number', () => {
expect(() => applyDefaults(42 as any, { a: 1 })).toThrow(TypeError);
});

// Test case 5: Handle non-object input for the first parameter (string)
it('5. should throw a TypeError if the first input is a string', () => {
// Test case 7: Handle non-object input for the first parameter (string)
it('7. should throw a TypeError if the first input is a string', () => {
expect(() => applyDefaults('string' as any, { a: 1 })).toThrow(TypeError);
});

// Test case 6: Handle non-object input for the first parameter (boolean)
it('6. should throw a TypeError if the first input is a boolean', () => {
// Test case 8: Handle non-object input for the first parameter (boolean)
it('8. should throw a TypeError if the first input is a boolean', () => {
expect(() => applyDefaults(true as any, { a: 1 })).toThrow(TypeError);
});

// Test case 7: Handle non-object input for the first parameter (null)
it('7. should throw a TypeError if the first input is null', () => {
// Test case 9: Handle non-object input for the first parameter (null)
it('9. should throw a TypeError if the first input is null', () => {
expect(() => applyDefaults(null as any, { a: 1 })).toThrow(TypeError);
});

// Test case 8: Handle non-object input for the first parameter (undefined)
it('8. should throw a TypeError if the first input is undefined', () => {
// Test case 10: Handle non-object input for the first parameter (undefined)
it('10. should throw a TypeError if the first input is undefined', () => {
expect(() => applyDefaults(undefined as any, { a: 1 })).toThrow(TypeError);
});

// Test case 9: Handle non-object input for the second parameter (number)
it('9. should throw a TypeError if the second input is a number', () => {
// Test case 11: Handle non-object input for the second parameter (number)
it('11. should throw a TypeError if the second input is a number', () => {
expect(() => applyDefaults({ a: 1 }, 42 as any)).toThrow(TypeError);
});

// Test case 10: Handle non-object input for the second parameter (string)
it('10. should throw a TypeError if the second input is a string', () => {
// Test case 12: Handle non-object input for the second parameter (string)
it('12. should throw a TypeError if the second input is a string', () => {
expect(() => applyDefaults({ a: 1 }, 'string' as any)).toThrow(TypeError);
});

// Test case 11: Handle non-object input for the second parameter (boolean)
it('11. should throw a TypeError if the second input is a boolean', () => {
// Test case 13: Handle non-object input for the second parameter (boolean)
it('13. should throw a TypeError if the second input is a boolean', () => {
expect(() => applyDefaults({ a: 1 }, true as any)).toThrow(TypeError);
});

// Test case 12: Handle non-object input for the second parameter (null)
it('12. should throw a TypeError if the second input is null', () => {
// Test case 14: Handle non-object input for the second parameter (null)
it('14. should throw a TypeError if the second input is null', () => {
expect(() => applyDefaults({ a: 1 }, null as any)).toThrow(TypeError);
});

// Test case 13: Handle non-object input for the second parameter (undefined)
it('13. should throw a TypeError if the second input is undefined', () => {
// Test case 15: Handle non-object input for the second parameter (undefined)
it('15. should throw a TypeError if the second input is undefined', () => {
expect(() => applyDefaults({ a: 1 }, undefined as any)).toThrow(TypeError);
});
});
121 changes: 39 additions & 82 deletions functionsUnittests/objectFunctions/deepEqual.test.ts
Original file line number Diff line number Diff line change
@@ -1,129 +1,86 @@
import { deepEqual } from '../../objectFunctions/deepEqual';

describe('deepEqual', () => {
// Test case 1: Compare two identical simple objects
it('1. should return true for two identical simple objects', () => {
// Test case 1: Compare two simple objects
it('1. should return true for two equal simple objects', () => {
const obj1 = { a: 1, b: 2 };
const obj2 = { a: 1, b: 2 };
const result = deepEqual(obj1, obj2);
const expected = true;
expect(result).toBe(expected);
expect(deepEqual(obj1, obj2)).toBe(true);
});

// Test case 2: Compare two different simple objects
it('2. should return false for two different simple objects', () => {
const obj1 = { a: 1, b: 2 };
const obj2 = { a: 1, b: 3 };
const result = deepEqual(obj1, obj2);
const expected = false;
expect(result).toBe(expected);
expect(deepEqual(obj1, obj2)).toBe(false);
});

// Test case 3: Compare two identical nested objects
it('3. should return true for two identical nested objects', () => {
// Test case 3: Compare two nested objects
it('3. should return true for two equal nested objects', () => {
const obj1 = { a: 1, b: { c: 2, d: 3 } };
const obj2 = { a: 1, b: { c: 2, d: 3 } };
const result = deepEqual(obj1, obj2);
const expected = true;
expect(result).toBe(expected);
expect(deepEqual(obj1, obj2)).toBe(true);
});

// Test case 4: Compare two different nested objects
it('4. should return false for two different nested objects', () => {
const obj1 = { a: 1, b: { c: 2, d: 3 } };
const obj2 = { a: 1, b: { c: 2, d: 4 } };
const result = deepEqual(obj1, obj2);
const expected = false;
expect(result).toBe(expected);
expect(deepEqual(obj1, obj2)).toBe(false);
});

// Test case 5: Compare two identical arrays
it('5. should return true for two identical arrays', () => {
// Test case 5: Compare two arrays
it('5. should return true for two equal arrays', () => {
const arr1 = [1, 2, 3];
const arr2 = [1, 2, 3];
const result = deepEqual(arr1, arr2);
const expected = true;
expect(result).toBe(expected);
expect(deepEqual(arr1, arr2)).toBe(true);
});

// Test case 6: Compare two different arrays
it('6. should return false for two different arrays', () => {
const arr1 = [1, 2, 3];
const arr2 = [1, 2, 4];
const result = deepEqual(arr1, arr2);
const expected = false;
expect(result).toBe(expected);
expect(deepEqual(arr1, arr2)).toBe(false);
});

// Test case 7: Compare two identical objects with arrays
it('7. should return true for two identical objects with arrays', () => {
const obj1 = { a: [1, 2, 3], b: 'test' };
const obj2 = { a: [1, 2, 3], b: 'test' };
const result = deepEqual(obj1, obj2);
const expected = true;
expect(result).toBe(expected);
// Test case 7: Compare objects with various data types
it('7. should return true for objects with equal various data types', () => {
const obj1 = { a: 1, b: 'string', c: true, d: null, e: undefined, f: [1, 2, 3], g: { h: 4 } };
const obj2 = { a: 1, b: 'string', c: true, d: null, e: undefined, f: [1, 2, 3], g: { h: 4 } };
expect(deepEqual(obj1, obj2)).toBe(true);
});

// Test case 8: Compare two different objects with arrays
it('8. should return false for two different objects with arrays', () => {
const obj1 = { a: [1, 2, 3], b: 'test' };
const obj2 = { a: [1, 2, 4], b: 'test' };
const result = deepEqual(obj1, obj2);
const expected = false;
expect(result).toBe(expected);
// Test case 8: Compare objects with symbols
it('8. should return true for objects with equal symbols', () => {
const sym1 = Symbol('sym1');
const sym2 = Symbol('sym2');
const obj1 = { [sym1]: 1, [sym2]: 2 };
const obj2 = { [sym1]: 1, [sym2]: 2 };
expect(deepEqual(obj1, obj2)).toBe(true);
});

// Test case 9: Compare two identical objects with functions
it('9. should return true for two identical objects with functions', () => {
const obj1 = { a: () => 1, b: 'test' };
const obj2 = { a: () => 1, b: 'test' };
const result = deepEqual(obj1, obj2);
const expected = true;
expect(result).toBe(expected);
// Test case 9: Handle non-object input (number)
it('9. should return false if one input is a number', () => {
expect(deepEqual(42 as any, { a: 1 })).toBe(false);

Check warning on line 64 in functionsUnittests/objectFunctions/deepEqual.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/deepEqual.test.ts#L64

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 10: Compare two different objects with functions
it('10. should return false for two different objects with functions', () => {
const obj1 = { a: () => 1, b: 'test' };
const obj2 = { a: () => 2, b: 'test' };
const result = deepEqual(obj1, obj2);
const expected = false;
expect(result).toBe(expected);
// Test case 10: Handle non-object input (string)
it('10. should return false if one input is a string', () => {
expect(deepEqual('string' as any, { a: 1 })).toBe(false);

Check warning on line 69 in functionsUnittests/objectFunctions/deepEqual.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/deepEqual.test.ts#L69

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 11: Compare two identical objects with symbols
it('11. should return true for two identical objects with symbols', () => {
const obj1 = { a: Symbol('a'), b: 'test' };
const obj2 = { a: Symbol('a'), b: 'test' };
const result = deepEqual(obj1, obj2);
const expected = true;
expect(result).toBe(expected);
// Test case 11: Handle non-object input (boolean)
it('11. should return false if one input is a boolean', () => {
expect(deepEqual(true as any, { a: 1 })).toBe(false);

Check warning on line 74 in functionsUnittests/objectFunctions/deepEqual.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/deepEqual.test.ts#L74

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 12: Compare two different objects with symbols
it('12. should return false for two different objects with symbols', () => {
const obj1 = { a: Symbol('a'), b: 'test' };
const obj2 = { a: Symbol('b'), b: 'test' };
const result = deepEqual(obj1, obj2);
const expected = false;
expect(result).toBe(expected);
// Test case 12: Handle non-object input (null)
it('12. should return false if one input is null', () => {
expect(deepEqual(null as any, { a: 1 })).toBe(false);

Check warning on line 79 in functionsUnittests/objectFunctions/deepEqual.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/deepEqual.test.ts#L79

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});

// Test case 13: Compare two identical objects with BigInt values
it('13. should return true for two identical objects with BigInt values', () => {
const obj1 = { a: BigInt(1), b: 'test' };
const obj2 = { a: BigInt(1), b: 'test' };
const result = deepEqual(obj1, obj2);
const expected = true;
expect(result).toBe(expected);
});

// Test case 14: Compare two different objects with BigInt values
it('14. should return false for two different objects with BigInt values', () => {
const obj1 = { a: BigInt(1), b: 'test' };
const obj2 = { a: BigInt(2), b: 'test' };
const result = deepEqual(obj1, obj2);
const expected = false;
expect(result).toBe(expected);
// Test case 13: Handle non-object input (undefined)
it('13. should return false if one input is undefined', () => {
expect(deepEqual(undefined as any, { a: 1 })).toBe(false);

Check warning on line 84 in functionsUnittests/objectFunctions/deepEqual.test.ts

View check run for this annotation

codefactor.io / CodeFactor

functionsUnittests/objectFunctions/deepEqual.test.ts#L84

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
});
});
54 changes: 32 additions & 22 deletions functionsUnittests/objectFunctions/deepFreeze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,61 @@ describe('deepFreeze', () => {
// Test case 1: Deep freeze a simple object
it('1. should deep freeze a simple object', () => {
const obj = { a: 1, b: 2 };
const result = deepFreeze(obj);
expect(Object.isFrozen(result)).toBe(true);
expect(() => { (result as any).a = 3; }).toThrow(TypeError);
const frozenObj = deepFreeze(obj);
expect(Object.isFrozen(frozenObj)).toBe(true);
expect(() => { frozenObj.a = 2; }).toThrow(TypeError);
});

// Test case 2: Deep freeze a nested object
it('2. should deep freeze a nested object', () => {
const obj = { a: 1, b: { c: 2, d: 3 } };
const result = deepFreeze(obj);
expect(Object.isFrozen(result)).toBe(true);
expect(Object.isFrozen(result.b)).toBe(true);
expect(() => { (result.b as any).c = 4; }).toThrow(TypeError);
const frozenObj = deepFreeze(obj);
expect(Object.isFrozen(frozenObj)).toBe(true);
expect(Object.isFrozen(frozenObj.b)).toBe(true);
expect(() => { frozenObj.b.c = 3; }).toThrow(TypeError);
});

// Test case 3: Deep freeze an array
it('3. should deep freeze an array', () => {
const arr = [1, 2, { a: 3 }];
const result = deepFreeze(arr);
expect(Object.isFrozen(result)).toBe(true);
expect(Object.isFrozen(result[2])).toBe(true);
expect(() => { (result[2] as any).a = 4; }).toThrow(TypeError);
const frozenArr = deepFreeze(arr);
expect(Object.isFrozen(frozenArr)).toBe(true);
expect(Object.isFrozen(frozenArr[2])).toBe(true);
expect(() => { frozenArr[0] = 4; }).toThrow(TypeError);
});

// Test case 4: Handle non-object input (number)
it('4. should throw a TypeError if input is a number', () => {
// Test case 4: Deep freeze an object with various data types
it('4. should deep freeze an object with various data types', () => {
const obj = { a: 1, b: 'string', c: true, d: null, e: undefined, f: [1, 2, 3], g: { h: 4 } };
const frozenObj = deepFreeze(obj);
expect(Object.isFrozen(frozenObj)).toBe(true);
expect(Object.isFrozen(frozenObj.f)).toBe(true);
expect(Object.isFrozen(frozenObj.g)).toBe(true);
expect(() => { frozenObj.a = 2; }).toThrow(TypeError);
});

// Test case 5: Handle non-object input (number)
it('5. should throw a TypeError if input is a number', () => {
expect(() => deepFreeze(42 as any)).toThrow(TypeError);
});

// Test case 5: Handle non-object input (string)
it('5. should throw a TypeError if input is a string', () => {
// Test case 6: Handle non-object input (string)
it('6. should throw a TypeError if input is a string', () => {
expect(() => deepFreeze('string' as any)).toThrow(TypeError);
});

// Test case 6: Handle non-object input (boolean)
it('6. should throw a TypeError if input is a boolean', () => {
// Test case 7: Handle non-object input (boolean)
it('7. should throw a TypeError if input is a boolean', () => {
expect(() => deepFreeze(true as any)).toThrow(TypeError);
});

// Test case 7: Handle non-object input (null)
it('7. should throw a TypeError if input is null', () => {
// Test case 8: Handle non-object input (null)
it('8. should throw a TypeError if input is null', () => {
expect(() => deepFreeze(null as any)).toThrow(TypeError);
});

// Test case 8: Handle non-object input (undefined)
it('8. should throw a TypeError if input is undefined', () => {
// Test case 9: Handle non-object input (undefined)
it('9. should throw a TypeError if input is undefined', () => {
expect(() => deepFreeze(undefined as any)).toThrow(TypeError);
});
});
});
Loading
Loading