| 1 |
import chai from 'chai'; |
| 2 |
const { expect } = chai; |
| 3 |
import find from '../../src/utils/find'; |
| 4 |
|
| 5 |
describe('utils/find', () => { |
| 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(find(arr, el => el.id === 1)).to.deep.equal({ id: 1, value: '1v' }); |
| 15 |
}); |
| 16 |
|
| 17 |
it('should return the fist found element', () => { |
| 18 |
expect(find(arr, el => el.value === '2v')).to.deep.equal({ |
| 19 |
id: 2, |
| 20 |
value: '2v', |
| 21 |
}); |
| 22 |
}); |
| 23 |
|
| 24 |
it('should return undefined if nothing is found', () => { |
| 25 |
expect(find(arr, el => el.value === '3v')).to.equal(undefined); |
| 26 |
}); |
| 27 |
}); |