Skip to content

Commit

Permalink
feat(bezier-react): add test case to array
Browse files Browse the repository at this point in the history
  • Loading branch information
SEOKKAMONI committed Dec 4, 2023
1 parent 3f02f3a commit 1db1a0f
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions packages/bezier-react/src/utils/array.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
import {
compact,
flattenDeep,
isLastArrayIndex,
} from './array'

describe('arrayUtils', () => {
describe('compact', () => {
it('should remove falsy item', () => {
const array = [0, 1, false, 2, '', 3]
expect(compact(array)).toEqual([1, 2, 3])
})
describe('isLastArrayIndex', () => {
it('should return true when the last array index', () => {
const arr = [0, 1, 2, 3, 4]

const result = isLastArrayIndex(arr, 4)

expect(result).toBe(true)
})

it('should return false when not the last array index', () => {
const arr = [0, 1, 2, 3, 4]

const result = isLastArrayIndex(arr, 1)

expect(result).toBe(false)
})
})

describe('compact', () => {
it('should remove falsy item', () => {
const array = [0, 1, false, 2, '', 3]
expect(compact(array)).toEqual([1, 2, 3])
})
})

describe('flattenDeep', () => {
it('should return flatten array', () => {
const array = [1, [2, [3, [4]], 5]]
expect(flattenDeep(array)).toEqual([1, 2, 3, 4, 5])
})
describe('flattenDeep', () => {
it('should return flatten array', () => {
const array = [1, [2, [3, [4]], 5]]
expect(flattenDeep(array)).toEqual([1, 2, 3, 4, 5])
})
})

0 comments on commit 1db1a0f

Please sign in to comment.