-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bezier-react): add test case to array
- Loading branch information
1 parent
3f02f3a
commit 1db1a0f
Showing
1 changed file
with
28 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
}) | ||
}) |