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

feat: add isTimePassed function to TestUtils.ts #234

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
});
});
});