Skip to content

Commit

Permalink
test(array): improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LoTwT committed Nov 18, 2024
1 parent 269b2c7 commit 662f52e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ it('normalizeToArray', () => {

it('removeItem', () => {
const arr = [1, 2, 3, 4]
removeItem(arr, 2)
const removed = removeItem(arr, 2)
expect(arr).toEqual([1, 3, 4])
expect(removed).toEqual([2])

expect(removeItem([], undefined)).toEqual(undefined)
expect(removeItem([1], 2)).toEqual(undefined)
})

it('toggleItem', () => {
Expand Down Expand Up @@ -72,11 +76,17 @@ describe('find', () => {
expect(index).toBe(4)
})

it('not found', () => {
it('not found from start', () => {
const [item, index] = find([1, 2, 3, 4, 3], (item) => item === 5)
expect(item).toBe(null)
expect(index).toBe(-1)
})

it('not found from end', () => {
const [item, index] = find([1, 2, 3, 4, 3], (item) => item === 5, 'end')
expect(item).toBe(null)
expect(index).toBe(-1)
})
})

it('at', () => {
Expand Down

0 comments on commit 662f52e

Please sign in to comment.