Default to 2 second wait for IfExists variants

This commit is contained in:
Andy Balaam 2026-04-16 16:20:25 +01:00
parent f7944cf85f
commit 81c4e9c2c1

View File

@ -44,7 +44,9 @@ class Toasts {
*
* @param title - Expected title of the toast.
* @param timeout - Time in ms before we give up and decide the toast does
* not exist. Defaults to `timeout` in `TestConfig.expect`.
* not exist. If `required` is true, defaults to `timeout`
* in `TestConfig.expect`. Otherwise, defaults to 2000 (2
* seconds).
* @param required - If true, fail the test (throw an exception) if the
* toast is not visible. Otherwise, just return null if
* the toast is not visible.
@ -58,6 +60,10 @@ class Toasts {
await expect(toast).toBeVisible({ timeout });
return toast;
} else {
// If we don't set a timeout, waitFor will wait forever. Since
// required is false, we definitely don't want to wait forever.
timeout = timeout ?? 2000;
try {
await toast.waitFor({ state: "visible", timeout });
return toast;
@ -126,7 +132,9 @@ class Toasts {
* "primary", which will accept the toast, or "secondary",
* which will reject it.
* @param timeout - Time in ms before we give up and decide the toast does
* not exist. Defaults to `timeout` in `TestConfig.expect`.
* not exist. If `required` is true, defaults to `timeout`
* in `TestConfig.expect`. Otherwise, defaults to 2000 (2
* seconds).
* @param required - If true, fail the test (throw an exception) if the
* toast is not visible. Otherwise, just return after
* `timeout` if the toast is not visible.