File size: 889 Bytes
d9494a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { findByProperty } from '@/utils/array/findByProperty';

describe('findByProperty', () => {
  it('should find item matching the value', () => {
    const items = [
      { id: '1', status: 'active' },
      { id: '2', status: 'inactive' },
    ];

    const result = items.find(findByProperty('status', 'inactive'));

    expect(result).toEqual({ id: '2', status: 'inactive' });
  });

  it('should return undefined when no match exists', () => {
    const items = [{ id: '1', name: 'Alice' }];

    const result = items.find(findByProperty('name', 'Bob'));

    expect(result).toBeUndefined();
  });

  it('should handle null match value', () => {
    const items = [
      { id: '1', name: null as string | null },
      { id: '2', name: 'Bob' },
    ];

    const result = items.find(findByProperty('name', null));

    expect(result).toEqual({ id: '1', name: null });
  });
});