uppy/packages/@uppy/utils/src/findIndex.test.js
Antoine du Hamel 51ecc66e64
@uppy/utils: refactor to TS (#4699)
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
Co-authored-by: Nick Rutten <2504906+nickrttn@users.noreply.github.com>
Co-authored-by: Murderlon <merlijn@soverin.net>
Co-authored-by: Artur Paikin <artur@arturpaikin.com>
2023-11-06 15:01:50 +01:00

16 lines
622 B
JavaScript

import { describe, expect, it } from 'vitest'
import findIndex from './findIndex.js'
describe('findIndex', () => {
it('should return index of an object in an array, that matches a predicate', () => {
const arr = [{ name: 'foo' }, { name: 'bar' }, { name: '123' }]
const index = findIndex(arr, (item) => item.name === 'bar')
expect(index).toEqual(1)
})
it('should return -1 when no object in an array matches a predicate', () => {
const arr = [{ name: 'foo' }, { name: 'bar' }, { name: '123' }]
const index = findIndex(arr, (item) => item.name === 'hello')
expect(index).toEqual(-1)
})
})