Expectation
A value you are checking in a test, which you get from test.expect and then compare with checks like to_be.
A value you are checking in a test, which you get from test.expect and then compare with checks like to_be.
Checks that the value is exactly the expected one, comparing them with ==.
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 ==.Checks that a table has the same contents as the expected table, even if it is a different table.
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.Checks that the value is nil, meaning there is nothing there.
test.expect(nil):to_be_nil()Use it forchecking that an empty inventory slot gives back no item at all.
Checks that the value is anything at all except nil or false.
test.expect(true):to_be_truthy()Use it forchecking that a value is neither nil nor false.
Calls a function and checks that it errors, with your message in the error if you give one.
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.Checks that a number is close to another, to a number of decimal places, 2 by default.
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.