Improve isIterable() UT
[e-mobility-charging-stations-simulator.git] / test / utils / UtilsTest.ts
index 45ba4eb03bba02b78277c0cf6998934e89096d50..987ba7fbb055e701fc4af28a2639781995a09778 100644 (file)
@@ -1,5 +1,6 @@
 import expect from 'expect';
 
+import Constants from '../../src/utils/Constants';
 import Utils from '../../src/utils/Utils';
 
 describe('Utils test suite', () => {
@@ -107,11 +108,19 @@ describe('Utils test suite', () => {
     let randomInteger = Utils.getRandomInteger();
     expect(Number.isSafeInteger(randomInteger)).toBe(true);
     expect(randomInteger).toBeGreaterThanOrEqual(0);
-    expect(randomInteger).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
+    expect(randomInteger).toBeLessThanOrEqual(Constants.MAX_RANDOM_INTEGER);
     expect(randomInteger).not.toEqual(Utils.getRandomInteger());
-    expect(() => Utils.getRandomInteger(0, 1)).toThrowError(new RangeError('Invalid interval'));
-    expect(() => Utils.getRandomInteger(-1)).toThrowError(new RangeError('Invalid interval'));
-    expect(() => Utils.getRandomInteger(0, -1)).toThrowError(new RangeError('Invalid interval'));
+    expect(() => Utils.getRandomInteger(0, 1)).toThrowError(
+      'The value of "max" is out of range. It must be greater than the value of "min" (1). Received 1'
+    );
+    expect(() => Utils.getRandomInteger(-1)).toThrowError(
+      'The value of "max" is out of range. It must be greater than the value of "min" (0). Received 0'
+    );
+    expect(() => Utils.getRandomInteger(Constants.MAX_RANDOM_INTEGER + 1)).toThrowError(
+      `The value of "max" is out of range. It must be <= ${
+        Constants.MAX_RANDOM_INTEGER + 1
+      }. Received 281_474_976_710_656`
+    );
     randomInteger = Utils.getRandomInteger(2, 1);
     expect(randomInteger).toBeGreaterThanOrEqual(1);
     expect(randomInteger).toBeLessThanOrEqual(2);
@@ -137,15 +146,13 @@ describe('Utils test suite', () => {
   });
 
   it('Verify isIterable()', () => {
-    expect(Utils.isIterable('')).toBe(false);
+    expect(Utils.isIterable('')).toBe(true);
     expect(Utils.isIterable(' ')).toBe(true);
     expect(Utils.isIterable('test')).toBe(true);
     expect(Utils.isIterable(null)).toBe(false);
     expect(Utils.isIterable(undefined)).toBe(false);
-    expect(Utils.isIterable(0)).toBe(false);
-    expect(Utils.isIterable({})).toBe(false);
+    expect(Utils.isIterable([0, 1])).toBe(true);
     expect(Utils.isIterable({ 1: 1 })).toBe(false);
-    expect(Utils.isIterable([])).toBe(true);
     expect(Utils.isIterable(new Map())).toBe(true);
     expect(Utils.isIterable(new Set())).toBe(true);
     expect(Utils.isIterable(new WeakMap())).toBe(false);