JestUtils
Utility methods for writing Jest specs.
Functions
afterThis
JestUtils.afterThis(job: MaidTask) → () → ()--
Cancels the queued cleanup. Safe to call more than once.
Queues a maid task to be cleaned up once the current test finishes. Tasks unwind in reverse of the order they were queued, so teardown mirrors setup the way it would if each task were cleaned up right after the code it undoes.
it("reads back what it wrote", function()
local store = DataStore.new()
JestUtils.afterThis(store)
local handle = store:GetHandle()
JestUtils.afterThis(handle)
expect(handle:Read()).toEqual(nil)
end)
Returns a function that removes the task from the queue again, so an object that outlives its own registration can disown the cleanup instead of being destroyed twice.
local maid = Maid.new()
maid:GiveTask(JestUtils.afterThis(maid))
Every queued task runs even if an earlier one throws, and the failures are reported together against the test that queued them. Tasks queued while the stack is unwinding run before the ones still below them.