diff --git a/src/commons/TestUtils.ts b/src/commons/TestUtils.ts index 46dd33c71..9e47b01ec 100644 --- a/src/commons/TestUtils.ts +++ b/src/commons/TestUtils.ts @@ -31,6 +31,18 @@ export namespace TestUtils { return str.replace(/[^0-9]/g, ''); } + /** + * Check if number of minutes passed from given time till current time + * @param countDate date to count from + * @param numOfMinutes number of minutes to count + * @private + */ + export function isTimePassed(countDate: Date, numOfMinutes: number): boolean { + const timeInMs = numOfMinutes * 60 * 1000; /* ms */ + + return new Date().valueOf() - countDate.valueOf() > timeInMs; + } + /** * Return generic type of data by provided file path * path File located in wdio config file diff --git a/src/test/specs/TestUtilsSpec.ts b/src/test/specs/TestUtilsSpec.ts index 56904a034..ebed69249 100644 --- a/src/test/specs/TestUtilsSpec.ts +++ b/src/test/specs/TestUtilsSpec.ts @@ -30,4 +30,15 @@ describe('TestUtilsSpec', () => { assert.equal(Number(TestUtils.extractNumbersFromString(str)), expectedNumber); }); }); + describe('isTimePassed', () => { + it('expect to return true', () => { + const expectedDate = new Date(2000, 1); + assert.isTrue(TestUtils.isTimePassed(expectedDate, 5)); + }); + + it('expect to return false', () => { + const expectedDate = new Date(3000, 1); + assert.isNotTrue(TestUtils.isTimePassed(expectedDate, 5)); + }); + }); });