Skip to main content

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(
promisePromise,
timeoutnumber?--

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.

awaitValue

PromiseTestUtils.awaitValue(
predicate() → boolean,
timeoutnumber?--

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(
promisePromise,
timeoutnumber?--

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.

Show raw api
{
    "functions": [
        {
            "name": "awaitSettled",
            "desc": "Yields until the promise settles (resolves or rejects) or the timeout elapses. Races the promise\nagainst a timeout instead of polling.",
            "params": [
                {
                    "name": "promise",
                    "desc": "",
                    "lua_type": "Promise"
                },
                {
                    "name": "timeout",
                    "desc": "Defaults to 5 seconds",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "true if the promise settled, false if it timed out",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 27,
                "path": "src/promise/src/Shared/PromiseTestUtils.lua"
            }
        },
        {
            "name": "awaitValue",
            "desc": "Yields until the predicate returns a truthy value or the timeout elapses. Used when the awaited\ncondition is observable state rather than a promise.",
            "params": [
                {
                    "name": "predicate",
                    "desc": "",
                    "lua_type": "() -> boolean"
                },
                {
                    "name": "timeout",
                    "desc": "Defaults to 5 seconds",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "The final predicate result",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 55,
                "path": "src/promise/src/Shared/PromiseTestUtils.lua"
            }
        },
        {
            "name": "awaitOutcome",
            "desc": "Attaches resolve/reject handlers synchronously (so the rejection is always handled and never\nsurfaces as an uncaught error) and yields for the outcome.",
            "params": [
                {
                    "name": "promise",
                    "desc": "",
                    "lua_type": "Promise"
                },
                {
                    "name": "timeout",
                    "desc": "Defaults to 5 seconds",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "\"resolved\" | \"rejected\" | \"pending\""
                },
                {
                    "desc": "The resolved value or rejection error",
                    "lua_type": "any"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 72,
                "path": "src/promise/src/Shared/PromiseTestUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "PromiseTestUtils",
    "desc": "Test helpers for awaiting promises with a bounded timeout, so a hung promise fails the test\ninstead of freezing the runner. Awaiting races the promise against a timeout rather than polling\nwith `task.wait()`.",
    "source": {
        "line": 9,
        "path": "src/promise/src/Shared/PromiseTestUtils.lua"
    }
}