PromiseTestUtils
Test helpers for awaiting promises with a bounded timeout, so a hung promise fails the test
instead of freezing the runner. Awaiting races the promise against a timeout rather than polling
with task.wait().
Functions
awaitSettled
PromiseTestUtils.awaitSettled(timeout: number?--
Defaults to 5 seconds
) → boolean--
true if the promise settled, false if it timed out
Yields until the promise settles (resolves or rejects) or the timeout elapses. Races the promise against a timeout instead of polling.
awaitFulfilled
PromiseTestUtils.awaitFulfilled(promise: Promise.Promise<T...>,timeout: number?) → any
Yields until the promise fulfills and returns the first value it resolved with. Errors if the promise
rejects, or is still pending once the timeout (5 seconds by default) elapses, so a test fails at the
await instead of carrying a missing value forward. Only the first value comes back so the call can be
passed straight to expect, which takes one argument.
local dataStore = PromiseTestUtils.awaitFulfilled(playerDataStoreService:PromiseDataStore(player))
awaitRejected
PromiseTestUtils.awaitRejected(promise: Promise.Promise<T...>,timeout: number?) → anyYields until the promise rejects and returns the first value it rejected with. Errors if the promise fulfills, or is still pending once the timeout (5 seconds by default) elapses.
local err = PromiseTestUtils.awaitRejected(dataStore:Save())
awaitValue
PromiseTestUtils.awaitValue(predicate: () → boolean,timeout: number?--
Defaults to 5 seconds
) → boolean--
The final predicate result
Yields until the predicate returns a truthy value or the timeout elapses. Used when the awaited condition is observable state rather than a promise.
awaitOutcome
PromiseTestUtils.awaitOutcome(timeout: number?--
Defaults to 5 seconds
) → ("resolved" | "rejected" | "pending",any--
The resolved value or rejection error
)Attaches resolve/reject handlers synchronously (so the rejection is always handled and never surfaces as an uncaught error) and yields for the outcome.