Globals
In your test files, Lest puts each of these methods and objects into the global environment. You don't have to require or import anything to use them.
Functions
afterAll(fn: fun(), timeout?: number)
Runs a function after all tests in this file have completed.
You can provide an optional timeout
(in milliseconds) to specify how long to wait before aborting the callback.
The default timeout is 5 seconds.
This is often useful if you want to clean up some global setup state that is shared across tests.
For example:
local globalDatabase = makeGlobalDatabase()
local function cleanUpDatabase(db)
db:cleanUp()
end
afterAll(function()
cleanUpDatabase(globalDatabase)
end)
test("can find things", function()
globalDatabase:find("thing", {}, function(results)
expect(results.length).toBeGreaterThan(0)
end)
end)
test("can insert a thing", function()
globalDatabase:insert("thing", makeThing(), function(response)
expect(response.success).toBeTruthy()
end)
end)
Here the afterAll
ensures that cleanUpDatabase
is called after all tests run.
If afterAll
is inside a describe
block, it runs at the end of the describe block.
If you want to run some cleanup after every test instead of after all tests, use afterEach
instead.
afterEach(fn: fun(), timeout?: number)
Runs a function after each tests in this file completes.
You can provide an optional timeout
(in milliseconds) to specify how long to wait before aborting the callback.
The default timeout is 5 seconds.
beforeAll(fn: fun(), timeout?: number)
Runs a function before running the tests in this file.
You can provide an optional timeout
(in milliseconds) to specify how long to wait before aborting the callback.
The default timeout is 5 seconds.
beforeEach(fn: fun(), timeout?: number)
Runs a function before running each test in this file.
You can provide an optional timeout
(in milliseconds) to specify how long to wait before aborting the callback.
The default timeout is 5 seconds.
describe(name: string, fn: fun())
Creates a block that groups related tests together.
If you register a function for any of the setup/teardown hooks (afterAll
, afterEach
, beforeAll
and beforeEach
)
inside the describe
, they'll only exist while running tests defined in that describe
block (or any nested describe
s).
describe.each(testCases: any[]): fun(name: string, fn: fun(...: any))
Data driven variant of describe
to reduce duplication when testing the same code with different data.
The returned function matches regular describe
, except the callback you pass to it will be run for each test case you define.
The value of each test case will be unpacked and passed to your callback.
This is essentially the same as calling describe
in a for loop.
describe.skip(name: string, fn: fun())
Also under the alias xdescribe
.
Dummy version of describe()
which doesn't run the given test suite.
It will appear in test results as being skipped (this is not implemented yet, see LEST-88).
describe.skip.each(testCases: any[]): fun(name: string, fn: fun(...: any))
Also under the alias xdescribe.each
.
Dummy version of describe.each()
which doesn't run the given test suite cases.
They will appear in test results as being skipped (this is not implemented yet, see LEST-88).
test(name: string, fn: fun(), timeout?: number)
Also under the alias it
.
Registers a new test with the given name.
You can provide an optional timeout
(in milliseconds) to specify how long to wait before aborting the callback.
The default timeout is 5 seconds.
test.each(testCases: any[]): fun(name: string, fn: fun(...: any), timeout?: number)
Also under the alias it.each
.
Data driven variant of test
to reduce duplication when testing the same code with different data.
The returned function matches regular test
, except the callback you pass to it will be run for each test case you define.
The value of each test case will be unpacked and passed to your callback.
This is essentially the same as calling test
in a for loop.
test.skip(name: string, fn: fun(), timeout?: number)
Also under the aliases: it.skip
, xtest
and xit
.
Dummy version of test()
which doesn't run the given test.
It will appear in test results as being skipped (this is not implemented yet, see LEST-88).
test.skip.each(testCases: any[]): fun(name: string, fn: fun(...: any), timeout?: number)
Also under the aliases: it.skip.each
, xtest.each
and xit.each
.
Dummy version of test.each()
which doesn't run the given test cases.
They will appear in test results as being skipped (this is not implemented yet, see LEST-88).