Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat: add isTimePassed function to TestUtils.ts (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixZilber authored Jun 28, 2021
1 parent 1e2abbe commit 9e26afc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/commons/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/test/specs/TestUtilsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
});

0 comments on commit 9e26afc

Please sign in to comment.