-
Notifications
You must be signed in to change notification settings - Fork 233
Fix #648: Add setDefaultWaitOptions
function
#658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,13 @@ import { | |
import { resolveAfter, callAfter } from '../helpers/promises' | ||
import { TimeoutError } from '../helpers/error' | ||
|
||
const DEFAULT_INTERVAL = 50 | ||
const DEFAULT_TIMEOUT = 1000 | ||
let defaultInterval: number | false = 50 | ||
let defaultTimeout: number | false = 1000 | ||
|
||
function setDefaultWaitOptions({ interval, timeout }: WaitOptions) { | ||
defaultInterval = interval ?? defaultInterval | ||
defaultTimeout = timeout ?? defaultTimeout | ||
} | ||
Comment on lines
-13
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need some way of resetting the defaults back to the initial values? I'm just thinking about someone that wants to update the defaults for a single test file so they set it in the The options I see are:
Or maybe both? Or maybe there's another option I'm not seeing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think exporting the constants makes more sense than a function imo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been wondering about new options into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mpeyper, can you expand on your idea? I will export initial constants otherwise |
||
|
||
function asyncUtils(act: Act, addResolver: (callback: () => void) => void): AsyncUtils { | ||
const wait = async (callback: () => boolean | void, { interval, timeout }: WaitOptions) => { | ||
|
@@ -55,7 +60,7 @@ function asyncUtils(act: Act, addResolver: (callback: () => void) => void): Asyn | |
|
||
const waitFor = async ( | ||
callback: () => boolean | void, | ||
{ interval = DEFAULT_INTERVAL, timeout = DEFAULT_TIMEOUT }: WaitForOptions = {} | ||
{ interval = defaultInterval, timeout = defaultTimeout }: WaitForOptions = {} | ||
) => { | ||
const safeCallback = () => { | ||
try { | ||
|
@@ -73,7 +78,7 @@ function asyncUtils(act: Act, addResolver: (callback: () => void) => void): Asyn | |
|
||
const waitForValueToChange = async ( | ||
selector: () => unknown, | ||
{ interval = DEFAULT_INTERVAL, timeout = DEFAULT_TIMEOUT }: WaitForValueToChangeOptions = {} | ||
{ interval = defaultInterval, timeout = defaultTimeout }: WaitForValueToChangeOptions = {} | ||
) => { | ||
const initialValue = selector() | ||
|
||
|
@@ -83,9 +88,7 @@ function asyncUtils(act: Act, addResolver: (callback: () => void) => void): Asyn | |
} | ||
} | ||
|
||
const waitForNextUpdate = async ({ | ||
timeout = DEFAULT_TIMEOUT | ||
}: WaitForNextUpdateOptions = {}) => { | ||
const waitForNextUpdate = async ({ timeout = defaultTimeout }: WaitForNextUpdateOptions = {}) => { | ||
let updated = false | ||
addResolver(() => { | ||
updated = true | ||
|
@@ -104,4 +107,4 @@ function asyncUtils(act: Act, addResolver: (callback: () => void) => void): Asyn | |
} | ||
} | ||
|
||
export { asyncUtils } | ||
export { asyncUtils, setDefaultWaitOptions } |
Uh oh!
There was an error while loading. Please reload this page.