describe
testdescribe(name: string, opts?: dhtest.DescribeOpts)Opens a suite; the it calls that follow belong to it until the next describe. Suites and their tests run one after another, in the order they are declared.
In the guide: Test it
test
datumhue pkg test runs the *_test.lua modules in a package's tests/ directory. Before it loads them it installs the globals below, which exist only during a test run. datumhue pkg new and datumhue pkg refresh write tests/test.d.lua, which gives your editor their types.
describe(name: string, opts?: dhtest.DescribeOpts)Opens a suite; the it calls that follow belong to it until the next describe. Suites and their tests run one after another, in the order they are declared.
In the guide: Test it
it(name: string, opts_or_body: dhtest.ItOpts | fun(), body?: fun())Registers a test: give the body second, or the options second and the body third. The body runs as a coroutine resumed once per frame, so it can wait with wait_frames and wait_until. Before it runs, math.randomseed is seeded from the test's full name and the run's seed, so its random numbers repeat from run to run, and adding a test does not change them.
In the guide: Test it
wait_frames(n: integer)Suspends the current test for n frames, at least one.
In the guide: Test it
wait_until(pred: fun(): boolean, timeout_frames?: integer)Suspends the current test until pred() returns a truthy value, checking once per frame. The test fails when timeout_frames frames pass first. timeout_frames defaults to 600.
In the guide: Test it
expect(value: any) -> dhtest.ExpectationReturns the matchers for value.
In the guide: Test it
fail(msg?: string)Fails the current test, with msg as the reason it prints.
skip(reason?: string)Marks the current test skipped, with reason, and stops its body.
expect(value) returns a table of matchers, each called with .. A matcher whose check fails raises, which fails the test and prints the mismatch.
dhtest.Expectation record 7 matchers
| Matcher | Description |
|---|---|
| .to_be(expected: any) | Passes when the value is expected (==). |
| .to_equal(expected: any) | Passes when the value equals expected key by key, through nested tables. |
| .to_be_truthy() | Passes when the value is neither nil nor false. |
| .to_be_falsy() | Passes when the value is nil or false. |
| .to_be_nil() | Passes when the value is nil. |
| .to_be_close(expected: number, tolerance?: number) | Passes when the value is a number within tolerance of expected. tolerance defaults to 1e-6. |
| .to_contain(needle: any) | Passes when the value is a string that contains needle, or an array with an element == to it. |
dhtest.DescribeOpts options 2 keys
| Key | Type | Default | Description |
|---|---|---|---|
| before_each | fun() | no default | Runs inside each test's coroutine before its body, and may wait. |
| after_each | fun() | no default | Runs after each test in a coroutine of its own, even when the body failed or timed out, and may wait. |
dhtest.ItOpts options 1 key
| Key | Type | Default | Description |
|---|---|---|---|
| timeout_frames | integer | 3600 | The frames the test's before_each and body may take together before the test fails. |