Skip to content

Commit bb9ad6a

Browse files
committed
test(common): Fix isEmptyArray behavior and update tests
1 parent d12e405 commit bb9ad6a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/common/test/utils/shared.utils.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ describe('Shared utils', () => {
200200
});
201201

202202
describe('isEmptyArray', () => {
203-
it('should return true when array is empty', () => {
203+
it('should return true when array is empty or not exists', () => {
204204
expect(isEmptyArray([])).to.be.true;
205+
expect(isEmptyArray(null)).to.be.true;
206+
expect(isEmptyArray(undefined)).to.be.true;
205207
});
206208

207209
it('should return false when array is not empty', () => {
@@ -211,8 +213,6 @@ describe('Shared utils', () => {
211213
});
212214

213215
it('should return false for non-array values', () => {
214-
expect(isEmptyArray(null)).to.be.false;
215-
expect(isEmptyArray(undefined)).to.be.false;
216216
expect(isEmptyArray({})).to.be.false;
217217
expect(isEmptyArray('')).to.be.false;
218218
expect(isEmptyArray(0)).to.be.false;

packages/common/utils/shared.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export const isNil = (val: unknown): val is null | undefined =>
5555
isUndefined(val) || val === null;
5656

5757
export const isEmptyArray = (array: unknown): boolean => {
58-
if (!Array.isArray(array)) {
59-
return false;
58+
if (isNil(array)) {
59+
return true;
6060
}
61-
return array.length === 0;
61+
return Array.isArray(array) && array.length === 0;
6262
};
6363

6464
export const isSymbol = (val: unknown): val is symbol =>

0 commit comments

Comments
 (0)