数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

24 lines
675 B

import { describe, expect, it } from '@jest/globals'
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)
})
})