Skip to content

Commit 758e72f

Browse files
author
Said Shah
committed
updated assert methods for tests and added regions
1 parent c1fdf04 commit 758e72f

1 file changed

Lines changed: 54 additions & 23 deletions

File tree

src/utilities/collection-utils.test.ts

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { CollectionUtils } from "./collection-utils";
33
import { ResultRecord } from "../view-models/result-record";
44

55
describe("CollectionUtils", () => {
6+
// -----------------------------------------------------------------------------------------
7+
// #region hasValues
8+
// -----------------------------------------------------------------------------------------
9+
610
describe("hasValues", () => {
711
test("when collections param is an array and has elements, it returns true", (): void => {
812
// Arrange
@@ -108,7 +112,13 @@ describe("CollectionUtils", () => {
108112
// Assert
109113
expect(result).toBeTrue();
110114
});
111-
}); // end hasValues
115+
});
116+
117+
// #endregion hasValues
118+
119+
// -----------------------------------------------------------------------------------------
120+
// #region isEmpty
121+
// -----------------------------------------------------------------------------------------
112122

113123
describe("isEmpty", () => {
114124
test(`when collections param is an array and has elements, it returns false`, (): void => {
@@ -213,7 +223,13 @@ describe("CollectionUtils", () => {
213223
// Assert
214224
expect(result).toBeFalse();
215225
});
216-
}); // end isEmpty()
226+
});
227+
228+
// #endregion isEmpty
229+
230+
// -----------------------------------------------------------------------------------------
231+
// #region isNotEmpty
232+
// -----------------------------------------------------------------------------------------
217233

218234
describe("#isNotEmpty", () => {
219235
test(`when collections param is an array and has elements, it returns true`, (): void => {
@@ -320,7 +336,13 @@ describe("CollectionUtils", () => {
320336
// Assert
321337
expect(result).toBeTrue();
322338
});
323-
}); // end isNotEmpty
339+
});
340+
341+
// #endregion isNotEmpty
342+
343+
// -----------------------------------------------------------------------------------------
344+
// #region length
345+
// -----------------------------------------------------------------------------------------
324346

325347
describe("#length", () => {
326348
test(`when collections param is an array and has elements, it returns the length`, (): void => {
@@ -331,7 +353,7 @@ describe("CollectionUtils", () => {
331353
const result = CollectionUtils.length(array);
332354

333355
// Assert
334-
expect(result).toBe(2);
356+
expect(result).toBe(array.length);
335357
});
336358

337359
test(`when collections param is null, it returns -1`, (): void => {
@@ -353,9 +375,16 @@ describe("CollectionUtils", () => {
353375
const result = CollectionUtils.length(list);
354376

355377
// Assert
356-
expect(result).toBe(2);
378+
expect(result).toBe(list.size);
357379
});
358380
})
381+
382+
// #endregion length
383+
384+
// -----------------------------------------------------------------------------------------
385+
// #region equalsBy
386+
// -----------------------------------------------------------------------------------------
387+
359388
describe("#equalsBy", () => {
360389
type TestType = { id: number };
361390
const selector = (t: TestType) => t.id;
@@ -420,6 +449,12 @@ describe("CollectionUtils", () => {
420449
});
421450
});
422451

452+
// #endregion equalsBy
453+
454+
// -----------------------------------------------------------------------------------------
455+
// #region removeElementAt
456+
// -----------------------------------------------------------------------------------------
457+
423458
describe("#removeElementAt", () => {
424459
it("when index i < 0, returns source array", () => {
425460
// Arrange
@@ -459,6 +494,12 @@ describe("CollectionUtils", () => {
459494
});
460495
});
461496

497+
// #endregion removeElementAt
498+
499+
// -----------------------------------------------------------------------------------------
500+
// #region replaceElementAt
501+
// -----------------------------------------------------------------------------------------
502+
462503
describe("#replaceElementAt", () => {
463504
it("Replaces element at specified index and returns a new array", () => {
464505
// Arrange
@@ -469,12 +510,8 @@ describe("CollectionUtils", () => {
469510
const result = CollectionUtils.replaceElementAt(arr, 1, "replaced");
470511

471512
// Assert
472-
const equals = CollectionUtils.equalsBy(
473-
(s: string) => s,
474-
result,
475-
expected
476-
);
477-
expect(equals).toBe(true);
513+
expect(result).not.toBe(arr);
514+
expect(result).toStrictEqual(expected);
478515
});
479516

480517
it("When source array has no values it, then returns the source array", () => {
@@ -497,12 +534,8 @@ describe("CollectionUtils", () => {
497534
const result = CollectionUtils.replaceElementAt(arr, 2, "replaced-test");
498535

499536
// Assert
500-
const equals = CollectionUtils.equalsBy(
501-
(s: string) => s,
502-
result,
503-
expected
504-
);
505-
expect(equals).toBe(true);
537+
expect(result).not.toBe(arr);
538+
expect(result).toStrictEqual(expected);
506539
})
507540

508541
it("When index is last element of source it, then returns new array with value at the end", () => {
@@ -514,12 +547,8 @@ describe("CollectionUtils", () => {
514547
const result = CollectionUtils.replaceElementAt(arr, 4, "replaced");
515548

516549
// Assert
517-
const equals = CollectionUtils.equalsBy(
518-
(s: string) => s,
519-
result,
520-
expected
521-
);
522-
expect(equals).toBe(true);
550+
expect(result).not.toBe(arr);
551+
expect(result).toStrictEqual(expected);
523552
})
524553

525554
it("When index i < 0, then returns the source array", () => {
@@ -533,4 +562,6 @@ describe("CollectionUtils", () => {
533562
expect(result).toBe(arr);
534563
})
535564
});
565+
566+
// #endregion replaceElementAt
536567
});

0 commit comments

Comments
 (0)