Skip to content

test(bezier-react): Improved array test coverage #1775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
isLastIndex,
} 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('isLastIndex', () => {
it('should return true when the last array index', () => {
const arr = [0, 1, 2, 3, 4]

const result = isLastIndex(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 = isLastIndex(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])
})
})
2 changes: 1 addition & 1 deletion packages/bezier-react/src/utils/array.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isArray } from './type'

export function isLastIndex(array: any[], index: number) {
export function isLastIndex(array: ArrayLike<unknown>, index: number) {
return array.length - 1 === index
}

Expand Down