Skip to main content

SignalTestUtils

Records what a signal fires so a test can assert on it with expect. Mirrors RxTestUtils for signals. Takes a Signal, an RBXScriptSignal, or anything else with a Connect method, such as an RxSignal. A typed RxSignal needs :: any at the call site, since its type cannot be named here.

local showingComplete = SignalTestUtils.countFires(controller.maid, transitionModel.ShowingComplete)

transitionModel:Show()

expect(showingComplete()).toBe(1)

Functions​

countFires​

SignalTestUtils.countFires(
maid: Maid,
signal: Signal<...any> | RBXScriptSignal
) → () → number

Returns a function that reports how many times the signal has fired. The connection is given to the maid.

collectFireList​

SignalTestUtils.collectFireList(
maid: Maid,
signal: Signal<(
T,
...any
)> | RBXScriptSignal
) → {T}

Returns a list of the first argument of every fire, in order. The connection is given to the maid. A fire with no argument leaves a hole, so count those with SignalTestUtils.countFires.

collectFireListTuples​

SignalTestUtils.collectFireListTuples(
maid: Maid,
signal: Signal<...any> | RBXScriptSignal
) → {{any}}

Returns a list with one entry per fire, each a list of every argument that fire carried, for signals that fire with more than one argument. The connection is given to the maid.

local purchases = SignalTestUtils.collectFireListTuples(controller.maid, service.GamePassPurchased)

-- ...

expect(purchases).toEqual({ { player, GAME_PASS_ID } })
Show raw api
{
    "functions": [
        {
            "name": "countFires",
            "desc": "Returns a function that reports how many times the signal has fired. The connection is given to\nthe maid.",
            "params": [
                {
                    "name": "maid",
                    "desc": "",
                    "lua_type": "Maid"
                },
                {
                    "name": "signal",
                    "desc": "",
                    "lua_type": "Signal<...any> | RBXScriptSignal"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "() -> number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 41,
                "path": "src/signal/src/Shared/Test/SignalTestUtils.lua"
            }
        },
        {
            "name": "collectFireList",
            "desc": "Returns a list of the first argument of every fire, in order. The connection is given to the maid.\nA fire with no argument leaves a hole, so count those with [SignalTestUtils.countFires].",
            "params": [
                {
                    "name": "maid",
                    "desc": "",
                    "lua_type": "Maid"
                },
                {
                    "name": "signal",
                    "desc": "",
                    "lua_type": "Signal<(T, ...any)> | RBXScriptSignal"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ T }"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 64,
                "path": "src/signal/src/Shared/Test/SignalTestUtils.lua"
            }
        },
        {
            "name": "collectFireListTuples",
            "desc": "Returns a list with one entry per fire, each a list of every argument that fire carried, for\nsignals that fire with more than one argument. The connection is given to the maid.\n\n```lua\nlocal purchases = SignalTestUtils.collectFireListTuples(controller.maid, service.GamePassPurchased)\n\n-- ...\n\nexpect(purchases).toEqual({ { player, GAME_PASS_ID } })\n```",
            "params": [
                {
                    "name": "maid",
                    "desc": "",
                    "lua_type": "Maid"
                },
                {
                    "name": "signal",
                    "desc": "",
                    "lua_type": "Signal<...any> | RBXScriptSignal"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ { any } }"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 95,
                "path": "src/signal/src/Shared/Test/SignalTestUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "SignalTestUtils",
    "desc": "Records what a signal fires so a test can assert on it with `expect`. Mirrors [RxTestUtils] for\nsignals. Takes a [Signal], an `RBXScriptSignal`, or anything else with a `Connect` method, such as an\n[RxSignal]. A typed RxSignal needs `:: any` at the call site, since its type cannot be named here.\n\n```lua\nlocal showingComplete = SignalTestUtils.countFires(controller.maid, transitionModel.ShowingComplete)\n\ntransitionModel:Show()\n\nexpect(showingComplete()).toBe(1)\n```",
    "source": {
        "line": 17,
        "path": "src/signal/src/Shared/Test/SignalTestUtils.lua"
    }
}