Skip to content

Commit

Permalink
fix: Add Promise<void> return type for expectation (#26)
Browse files Browse the repository at this point in the history
* fix: add Promise<void> 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: jsdom/jsdom#2304 (comment)).
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”).
  • Loading branch information
rvanmil authored Feb 6, 2020
1 parent a59b638 commit 6be6e2e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
}
}
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, timeout?: number, interval?: number): any;
export default function waitForExpect(expectation: () => void | Promise<void>, timeout?: number, interval?: number): any;
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const defaults = {
* @return Promise Promise to return a callback result
*/
const waitForExpect = function waitForExpect(
expectation: () => void,
expectation: () => void | Promise<void>,
timeout = defaults.timeout,
interval = defaults.interval
) {
Expand Down

0 comments on commit 6be6e2e

Please sign in to comment.