Debian Codegraph @

packages/popper/tests/unit/findIndex.js

raw
1 import chai from 'chai';
2 const { expect } = chai;
3 import findIndex from '../../src/utils/findIndex';
4
5 describe('utils/findIndex', () => {
6 const arr = [
7 { id: 1, value: '1v' },
8 { id: 2, value: '2v' },
9 { id: 3, value: '2v' },
10 { id: 4, value: '2v' },
11 ];
12
13 it('should find correct element in an array', () => {
14 expect(findIndex(arr, 'id', 1)).to.equal(0);
15 });
16
17 it('should return index of the fist found element', () => {
18 expect(findIndex(arr, 'value', '2v')).to.equal(1);
19 });
20
21 it('should return -1 if nothing is found', () => {
22 expect(findIndex(arr, 'value', '3v')).to.equal(-1);
23 });
24 });