Skip to content

Commit f2089bd

Browse files
author
Said Shah
committed
added tests for isEmpty and hasValues methods in CollectionUtils
1 parent d75df22 commit f2089bd

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

src/utilities/collection-utils.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ import { ResultRecord } from "../view-models/result-record";
44

55
describe("CollectionUtils", () => {
66
describe("hasValues", () => {
7+
test("when collections param is null, it returns false", (): void => {
8+
// Arrange
9+
const collection = null;
10+
11+
// Act
12+
const result = CollectionUtils.hasValues(collection);
13+
14+
// Assert
15+
expect(result).toBeFalse();
16+
});
17+
18+
test("when collections param is undefined, it returns false", (): void => {
19+
// Arrange
20+
const collection = undefined;
21+
22+
// Act
23+
const result = CollectionUtils.hasValues(collection);
24+
25+
// Assert
26+
expect(result).toBeFalse();
27+
});
28+
729
test("when collections param is an array and has elements, it returns true", (): void => {
830
// Arrange
931
const collection = [{}];
@@ -111,6 +133,28 @@ describe("CollectionUtils", () => {
111133
}); // end hasValues
112134

113135
describe("isEmpty", () => {
136+
test(`when collections is null, it returns true`, (): void => {
137+
// Arrange
138+
const collection = null;
139+
140+
// Act
141+
const result = CollectionUtils.isEmpty(collection);
142+
143+
// Assert
144+
expect(result).toBeTrue();
145+
});
146+
147+
test(`when collections is undefined, it returns true`, (): void => {
148+
// Arrange
149+
const collection = undefined;
150+
151+
// Act
152+
const result = CollectionUtils.isEmpty(collection);
153+
154+
// Assert
155+
expect(result).toBeTrue();
156+
});
157+
114158
test(`when collections param is an array and has elements, it returns false`, (): void => {
115159
// Arrange
116160
const collection = [{}];

src/utilities/collection-utils.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ const _equalsBy = function<T, V>(
5858
const _hasValues = (
5959
...collections: Array<any[] | List<any> | undefined>
6060
): boolean => {
61-
if (collections == null) {
62-
return false;
63-
}
6461

6562
let hasValues = false;
6663
collections.forEach((collection: any[] | List<any> | undefined) => {
@@ -85,9 +82,6 @@ const _hasValues = (
8582
const _isEmpty = (
8683
...collections: Array<any[] | List<any> | undefined>
8784
): boolean => {
88-
if (collections == null) {
89-
return true;
90-
}
9185

9286
let isEmpty = true;
9387

0 commit comments

Comments
 (0)