LogoRobo.js
Packages@robojs/mock

TestUsers

Class: TestUsers

Test helper for managing multiple users in a session

Constructors

new TestUsers()

new TestUsers(session): TestUsers

Parameters

ParameterType
sessionSession

Returns

TestUsers

Methods

allBots()

allBots(): MockUser[]

Get all bot users

Returns

MockUser[]

Array of bot users


allHumans()

allHumans(): MockUser[]

Get all non-bot users

Returns

MockUser[]

Array of human users


as()

as<T>(user, action): Promise<T>

Act as a specific user for a block of code Restores the original current user after the action completes

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
userstring | MockUserUser object or username string
action() => T | Promise<T>The action to perform as this user

Returns

Promise<T>

The result of the action


byId()

byId(userId): undefined | MockUser

Get user by ID

Parameters

ParameterTypeDescription
userIdstringThe user ID

Returns

undefined | MockUser

The user if found, undefined otherwise


byName()

byName(username): undefined | MockUser

Get user by username (convenience method)

Parameters

ParameterTypeDescription
usernamestringThe username to search for

Returns

undefined | MockUser

The user if found, undefined otherwise


create()

create(name, options?): MockUser

Create a test user with sensible defaults

Parameters

ParameterTypeDescription
namestringUsername for the new user
options?Partial<{ avatar: null | string; bot: boolean; status: "online" | "offline" | "idle" | "dnd"; }>Additional user options

Returns

MockUser

The created user


createMany()

createMany(names): MockUser[]

Create multiple test users at once

Parameters

ParameterTypeDescription
namesstring[]Array of usernames

Returns

MockUser[]

Array of created users


current()

current(): MockUser

Get the current acting user

Returns

MockUser

The current user


switchTo()

switchTo(user): MockUser

Switch to a different user as the current acting user

Parameters

ParameterTypeDescription
userstring | MockUserUser object or username string

Returns

MockUser

The switched user

On this page