scenario() declares a test of your bot, from a *.test.ts file of src/, and chapterjs test runs it against a Discord in memory. Everything on this page is imported from chapterjs/test.
src/checks/hello.test.ts
src/checks/hello.ts
How to test a bot, what is checked without a scenario and what the test server has is in the guide. This page lists what exists.
scenario()
*.test.ts file of src/: chapterjs test runs it against a Discord in memory, where the bot is in a server with a few people in it.
bot is the bot in its test server: bot.use() runs a command, bot.click() presses a button, bot.say() sends a message as someone, and what comes back says what the bot answered.
A file may export several scenarios, in a list too. The label is what the report shows: it can not be empty, and 120 characters is the most.
ScenarioDeclaration
Whatscenario() returns: a declaration the runner finds in the exports of a file.
TestBot
The bot of the project, running in a Discord in memory: one server, a few people, and everything the bot does kept where the test can read it.Every request the bot sent to Discord so far.
member()
role()
channel()
#general exists.
use()
{ on: message }, { on: member }; a message menu is used in the channel of its message). Resolves once the bot answered.
options is typed from the options of the command (OptionInputsOf): a text, a number, true or false, one of the choices, a TestMember for a user option, a TestRole for a role one, a TestChannel for a channel one, a TestFile for an attachment one. It may be left out when the command requires none. What Discord would not let a person send (a required option missing, a number out of its range, a text too long, a value that is not one of the choices) fails the scenario before the bot hears of it.
click()
reply.button('Confirm')) is clicked on that message, as a person would.
select()
values are texts for a menu of texts (its option values), people, roles or channels for the others; the min and max of the menu are enforced.
submit()
fields is typed from the fields of the form (FieldInputsOf): a text for a text field, a list of option values for a select or checkboxes one, one option value for a radio one, true or false for a checkbox, people, roles or channels for the others, files for a files field. A field left out stays empty; a required one left out fails the scenario, as the Discord app would refuse to send the form.
suggest()
say()
react()
join()
leave()
run()
settle()
waitForMessage()…) is left waiting, and use(), say(), click()… resolve meanwhile.
endWaits()
waitForMessage(), waitForClick()…) as if its time was up: time does not pass in the test server. Resolves once the bot handled it.
TestWhere
Who does something, and where.TestMemberOptions
How to make a person for a test.TestRoleOptions
TestChannelOptions
TestFile
A file someone attaches to a command or a form.TestReply
What the bot answered to a command, a button, a menu or a form. It has every check ofTestAssertions, and:
The select menus on it, in order.
isDeferred()
updatesMessage()
opensForm()
changesNothing()
button()
menu()
TestAssertions
What is checked of a message or an answer. Each check throws aTestFailure with a plain sentence when it fails, and returns what it checked otherwise, so checks chain.
says()
text (or matches it).
saysExactly()
text.
isEphemeral()
isPublic()
hasButton()
hasEmbed()
hasNoEmbed()
hasNoComponent()
TestMessage
A message in the test server. It has every check ofTestAssertions, and:
The select menus on it, in order.
button()
menu()
TestMember
A person in the test server.can()
hasRole()
TestRole
A role of the test server.TestChannel
A channel of the test server, a thread, or a private conversation.Every message in it that everyone sees, oldest first (deleted and ephemeral ones left out).
allows()
TestButton
A button on a message the bot sent.TestMenu
A select menu on a message the bot sent.TestForm
A form the bot opened.TestSuggestion
A suggestion the bot gave while someone typed in an option.Types
OptionInputsOf<Options>: the options of a command as a test fills them in. A required option can not be left out.FieldInputsOf<Fields>: the fields of a form as a test fills them in: a field left out stays empty.SelectInput: what a test picks in a menu: texts, or people, roles and channels.TestMenuTarget<Type>: what a menu command is used on in a test:{ on }, aTestMemberfor a'user'menu, aTestMessagefor a'message'menu.ButtonTarget: a button, as a test names it: the declaration, an instance, or one found on a message (reply.button('Confirm')).SelectTarget: a menu, the same way (reply.menu()).FormTarget<Fields>: a form, the same way (reply.form).TestChannelType:'text' | 'announcement' | 'voice' | 'category' | 'forum'.TestFailure: an expectation of a test that the bot did not meet. What every check throws, with a plain sentence: the report shows it with the line of the scenario.