Testing
ℹ️
Page is being worked on.
A built-in testing suite for Luau.
Properties
Functions
Properties
running
running: boolean
Whether the testing suite is running.
_FAILED
_FAILED: number
[Internal]
The number of tests that have failed.
_COUNT
_COUNT: number
[Internal]
The number of tests conducted.
_START
_START: number
[Internal]
The time the testing suite started. Based on os.clock()
.
Functions
test
testing.test(name: string, callback: () -> ()): ()
ℹ️
When the test suite is not running, the function will do nothing.
Conducts a test.
Parameters
name: string
- The name of the test.callback: () -> ()
- The function to run the test.- The function should throw an error if the test fails.
describe
testing.describe(name: string, callback: () -> ()): ()
ℹ️
When the test suite is not running, the function will do nothing.
Describes a test suite.
Parameters
name: string
- The name of the test suite.callback: () -> ()
- The function to run the test suite.- The function should not error, and should call test functions.
- If the function does error, it will still count as a fail.
defer
testing.defer(fn: () -> ()): ()
Defers a function.
Deferred function will be executed after a test completes. Useful for cleaning up resources.
Parameters
fn: () -> ()
- The function to defer.
expect
testing.expect(value: any): ExpectCases | FunctionalCases
Parameters
value: any
- The value to test.
Returns
ExpectCases
|FunctionalCases
- The object to test the value.
expected
testing.expected(value: any): ()
️⚠️
Can Error
Expects a value to be true or non nil.
Similar to assert(value)
Parameters
value: any
- The value to expect.- If the value is
false
, the test will fail.
- If the value is
Throws
- If the function fails, an error will be thrown.
expectEqual
testing.expectEqual(expected: any, value: any): ()
️⚠️
Can Error
Expects a value to equal another.
Similar to assert(value == expected, ...)
Parameters
expected: any
- The expected value.value: any
- The value to test.
Throws
- If the function fails, an error will be thrown.