Packages@robojs/mock
TestUsers
Class: TestUsers
Test helper for managing multiple users in a session
Constructors
new TestUsers()
new TestUsers(session): TestUsersParameters
| Parameter | Type |
|---|---|
session | Session |
Returns
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
| Parameter | Type | Description |
|---|---|---|
user | string | MockUser | User 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 | MockUserGet user by ID
Parameters
| Parameter | Type | Description |
|---|---|---|
userId | string | The user ID |
Returns
undefined | MockUser
The user if found, undefined otherwise
byName()
byName(username): undefined | MockUserGet user by username (convenience method)
Parameters
| Parameter | Type | Description |
|---|---|---|
username | string | The username to search for |
Returns
undefined | MockUser
The user if found, undefined otherwise
create()
create(name, options?): MockUserCreate a test user with sensible defaults
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Username for the new user |
options? | Partial<{ avatar: null | string; bot: boolean; status: "online" | "offline" | "idle" | "dnd"; }> | Additional user options |
Returns
The created user
createMany()
createMany(names): MockUser[]Create multiple test users at once
Parameters
| Parameter | Type | Description |
|---|---|---|
names | string[] | Array of usernames |
Returns
MockUser[]
Array of created users
current()
current(): MockUserGet the current acting user
Returns
The current user
switchTo()
switchTo(user): MockUserSwitch to a different user as the current acting user
Parameters
| Parameter | Type | Description |
|---|---|---|
user | string | MockUser | User object or username string |
Returns
The switched user
