Skip to content

The open alternative to Salesforce, designed for AI.

590 B
Raw Blame
import { mapArrayToObject } from '~/utils/array/mapArrayToObject';

describe('mapArrayToObject', () => {
  it('maps an array of objects to an object with computed keys', () => {
    const array = [
      { id: '1', value: 'one' },
      { id: '2', value: 'two' },
      { id: '3', value: 'three' },
    ];
    const computeItemKey = ({ id }: { id: string }) => id;

    const result = mapArrayToObject(array, computeItemKey);

    expect(result).toEqual({
      '1': { id: '1', value: 'one' },
      '2': { id: '2', value: 'two' },
      '3': { id: '3', value: 'three' },
    });
  });
});