From 6be6e2ed8e47fd5bc62ab2fc4bd39289c58f2f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20van=20Mil?= Date: Thu, 6 Feb 2020 11:38:40 +0100 Subject: [PATCH] fix: Add Promise return type for expectation (#26) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: add Promise return type for expectation Since 0.6.0 promises and async/await are supported and tested, but the return type of the expectation function did not yet reflect this change. * fix SecurityError when running tests Jest fails the tests with “SecurityError: localStorage is not available for opaque origins”. Setting the Jest configuration option "testURL" to "http://localhost/" fixes this (also see: https://github.com/jsdom/jsdom/issues/2304#issuecomment-485265830). It’s probably a good idea to upgrade dependencies and remove this option afterwards, since with the current release of Jest this option is no longer required (it defaults to "http://localhost/“ instead of “about:blank”). --- package.json | 3 ++- src/index.d.ts | 2 +- src/index.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 289b04f..da0c8ea 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "transform": { "^.+\\.(js|jsx|ts|tsx)$": "babel-jest" }, - "testRegex": "/src/.*\\.spec\\.(js|ts|tsx)$" + "testRegex": "/src/.*\\.spec\\.(js|ts|tsx)$", + "testURL": "http://localhost/" } } diff --git a/src/index.d.ts b/src/index.d.ts index c425252..049a6e1 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -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, timeout?: number, interval?: number): any; +export default function waitForExpect(expectation: () => void | Promise, timeout?: number, interval?: number): any; diff --git a/src/index.ts b/src/index.ts index 350f7cf..8d81984 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ const defaults = { * @return Promise Promise to return a callback result */ const waitForExpect = function waitForExpect( - expectation: () => void, + expectation: () => void | Promise, timeout = defaults.timeout, interval = defaults.interval ) {