Skip to content

Commit

Permalink
Return the result of the callback in the promise
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehb committed Dec 16, 2021
1 parent 6be6e2e commit 2e7924e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* @param interval Number Wait-between-retries interval, 50ms by default
* @return Promise Promise to return a callback result
*/
export default function waitForExpect(expectation: () => void | Promise<void>, timeout?: number, interval?: number): any;
export default function waitForExpect<T>(expectation: () => T | Promise<T>, timeout?: number, interval?: number): Promise<T>;
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const defaults = {
* @param interval Number Wait-between-retries interval, 50ms by default
* @return Promise Promise to return a callback result
*/
const waitForExpect = function waitForExpect(
expectation: () => void | Promise<void>,
const waitForExpect = function waitForExpect<T>(
expectation: () => T | Promise<T>,
timeout = defaults.timeout,
interval = defaults.interval
) {
Expand All @@ -37,7 +37,7 @@ const waitForExpect = function waitForExpect(
tries += 1;
try {
Promise.resolve(expectation())
.then(() => resolve())
.then(result => resolve(result))
.catch(rejectOrRerun);
} catch (error) {
rejectOrRerun(error);
Expand Down

0 comments on commit 2e7924e

Please sign in to comment.