Files
inji-wallet/shared/javascript.test.ts
Kaushik Gupta 33c6caa08a INJIMOB-3246 Code coverage for Inji-Wallet repo increase above 5% (#2108)
* INJIMOB-3246 Code coverage for Inji-Wallet repo increase above 5%

Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>

* INJIMOB-3246: added snapshot tests and coverage increased to +4%

Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>

* removed duplicated lines

Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>

* Added updateCredentialInformation tests

Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>

* added code rabbit changes

Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>

* removed platform-specific tests without mocking

Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>

* standardize mocks in VcItemContainerProfileImage tests

Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>

---------

Signed-off-by: Kaushik Gupta <kausgpt97@gmail.com>
2025-11-07 11:10:37 +05:30

74 lines
2.2 KiB
TypeScript

import {groupBy} from './javascript';
describe('javascript utils', () => {
describe('groupBy', () => {
it('should group elements based on predicate', () => {
const array = [1, 2, 3, 4, 5, 6];
const predicate = (num: number) => num % 2 === 0;
const [trueElements, falseElements] = groupBy(array, predicate);
expect(trueElements).toEqual([2, 4, 6]);
expect(falseElements).toEqual([1, 3, 5]);
});
it('should return empty arrays for empty input', () => {
const array: number[] = [];
const predicate = (num: number) => num > 0;
const [trueElements, falseElements] = groupBy(array, predicate);
expect(trueElements).toEqual([]);
expect(falseElements).toEqual([]);
});
it('should put all elements in true group when predicate always returns true', () => {
const array = ['a', 'b', 'c'];
const predicate = () => true;
const [trueElements, falseElements] = groupBy(array, predicate);
expect(trueElements).toEqual(['a', 'b', 'c']);
expect(falseElements).toEqual([]);
});
it('should put all elements in false group when predicate always returns false', () => {
const array = ['a', 'b', 'c'];
const predicate = () => false;
const [trueElements, falseElements] = groupBy(array, predicate);
expect(trueElements).toEqual([]);
expect(falseElements).toEqual(['a', 'b', 'c']);
});
it('should handle complex objects', () => {
const array = [
{name: 'John', age: 30},
{name: 'Jane', age: 25},
{name: 'Bob', age: 35},
];
const predicate = (person: {name: string; age: number}) =>
person.age >= 30;
const [trueElements, falseElements] = groupBy(array, predicate);
expect(trueElements).toEqual([
{name: 'John', age: 30},
{name: 'Bob', age: 35},
]);
expect(falseElements).toEqual([{name: 'Jane', age: 25}]);
});
it('should handle undefined array', () => {
const array = undefined as any;
const predicate = (num: number) => num > 0;
const [trueElements, falseElements] = groupBy(array, predicate);
expect(trueElements).toEqual([]);
expect(falseElements).toEqual([]);
});
});
});