From 1db1a0fd2769620ae70e923b9912f7e559cdf146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=9D=EC=A7=84?= Date: Mon, 4 Dec 2023 20:23:31 +0900 Subject: [PATCH] feat(bezier-react): add test case to array --- packages/bezier-react/src/utils/array.test.ts | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/packages/bezier-react/src/utils/array.test.ts b/packages/bezier-react/src/utils/array.test.ts index a9387d974e..1b2844d4b3 100644 --- a/packages/bezier-react/src/utils/array.test.ts +++ b/packages/bezier-react/src/utils/array.test.ts @@ -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]) }) })