x
This class is passed into test modules.
Functions
assertEqual
x.assertEqual(left: any,right: any) → ()Throws if left ~= right.
-- This will throw because 1 is not equal to 2.
assertEqual(1, 2)
test
x.test(name: string,callback: (context: {}) → ()) → ()Creates a new test inside of the current scope.
test("1 == 1", function()
assert(1 == 1)
end)
testFOCUS
x.testFOCUS(name: string,callback: (context: {}) → ()) → ()Creates a new test inside of the current scope. If any test is focused, only focused tests will run.
testFOCUS("1 == 1", function()
assert(1 == 1)
end)
testSKIP
x.testSKIP(name: string,callback: (context: {}) → ()) → ()Creates a new test inside of the current scope that will be skipped.
testSKIP("skip", function()
print("this will not print")
end)
beforeEach
x.beforeEach(callback: (context: {}) → ()) → ()
Runs callback before each test inside its scope runs. It's passed a context table unique to that test.
context can be used to share setup code across tests.
beforeEach(function(context)
context.maid = Maid.new()
end)
test(function(context)
assert(context.maid:isEmpty())
end)
afterEach
x.afterEach(callback: (context: {}) → ()) → ()
Runs callback after each test inside its scope runs. It's passed a context table which can be used to cleanup
state unique to the test.
afterEach(function(context)
context.object:destroy()
end)
nested
x.nested(name: string,callback: () → ()) → ()Creates a nested scope for tests. It can be used to group tests that are testing similar things.
nested("nested", function()
-- This `beforeEach` will only affect tests inside of this nested scope.
beforeEach(function() end)
test("nested test", function() end)
end)
shouldThrow
x.shouldThrow(callback: () → (),substring: string?) → ()Throws if the callback doesn't error or if the error does not contain substring.
-- This will not throw because the callback errors with a string containing "needle"
shouldThrow(function()
error("haystick with a needle")
end, "needle")