@usbx/test
Unit tests
local test = require("@usbx/test")
Groups tests under a name. The body runs at once, declares tests, hooks and other groups, and must not yield.
test.describe(name: string, body: () -> ()) -> ()
Use it forgrouping all the tests for your inventory module together under one name.
nameWhat the tests inside have in common.
bodyDeclares the tests and hooks of the group. It must not yield.
Declares a test. Its body runs later in its own thread and can yield, until its timeout (5 s of script time by default).
test.it(name: string, body: () -> (), options:
TestOptions?) -> ()
Use it forchecking one thing, like whether your shop module charges the right price.
nameWhat the test checks, as a sentence.
bodyThe test. It runs in its own thread and can yield.
optionsoptionalThe timeout, in seconds of script time.
Build a it calltimeout
test.before_each
function#Runs a function before each test of this group and of the groups inside it, outer groups first.
test.before_each(hook: () -> ()) -> ()
Use it forsetting up fresh state, such as an empty inventory, before each test.
hookRuns before each test; it can yield.
Runs a function after each test of this group and of the groups inside it, also after a failed test, inner groups first.
test.after_each(hook: () -> ()) -> ()
Use it forcleaning up the parts a test spawned, even when it failed, so the next test starts clean.
hookRuns after each test, also a failed one.
Starts checking a value: test.expect(value):to_be(expected).
Use it forchecking a result inside a test, like the damage a hit deals or the price of an item.