Skip to content
Untitled Sandbox - Developer Documentation
docs/types/Expectation

Expectation

A value you are checking in a test, which you get from test.expect and then compare with checks like to_be.

Fields

Expectation:to_be

method

Checks that the value is exactly the expected one, comparing them with ==.

Expectation:to_be(expected: any) -> ()
example
test.expect(1 + 1):to_be(2)

Use it forchecking that buying a sword costs exactly 50 tokens.

expectedThe value it must be, compared with ==.

Expectation:to_equal

method

Checks that a table has the same contents as the expected table, even if it is a different table.

Expectation:to_equal(expected: any) -> ()
example
test.expect({ 1, 2 }):to_equal({ 1, 2 })

Use it forchecking that a new player's starting inventory holds exactly the right items.

expectedThe value it must equal, tables compared deeply.

Expectation:to_be_nil

method

Checks that the value is nil, meaning there is nothing there.

Expectation:to_be_nil() -> ()
example
test.expect(nil):to_be_nil()

Use it forchecking that an empty inventory slot gives back no item at all.

Expectation:to_be_truthy

method

Checks that the value is anything at all except nil or false.

Expectation:to_be_truthy() -> ()
example
test.expect(true):to_be_truthy()

Use it forchecking that a value is neither nil nor false.

Expectation:to_throw

method

Calls a function and checks that it errors, with your message in the error if you give one.

Expectation:to_throw(message: string?) -> ()
example
test.expect(function() error("empty") end):to_throw("empty")

Use it forchecking that trying to buy something with too few tokens gives an error.

messageoptionalText the error must contain, or nil for any error.

Expectation:to_be_close_to

method

Checks that a number is close to another, to a number of decimal places, 2 by default.

Expectation:to_be_close_to(expected: number, digits: number?) -> ()
example
test.expect(0.1 + 0.2):to_be_close_to(0.3, 5)

Use it forchecking a distance or speed that has decimals, since those are rarely exact.

expectedThe number it must be close to.
digitsoptionalHow many decimal places must match, -15 to 15. 2 by default.
↑ ↓ moveEnter openEsc close