Skip to main content

x

This class is passed into test modules.

Functions

assertEqual

x.assertEqual(
leftany,
rightany
) → ()

Throws if left ~= right.

-- This will throw because 1 is not equal to 2.
assertEqual(1, 2)

test

x.test(
namestring,
callback(context{}) → ()
) → ()

Creates a new test inside of the current scope.

test("1 == 1", function()
	assert(1 == 1)
end)

testFOCUS

x.testFOCUS(
namestring,
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(
namestring,
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(
namestring,
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() → (),
substringstring?
) → ()

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")
Show raw api
{
    "functions": [
        {
            "name": "assertEqual",
            "desc": "Throws if `left ~= right`.\n\n```lua\n-- This will throw because 1 is not equal to 2.\nassertEqual(1, 2)\n```",
            "params": [
                {
                    "name": "left",
                    "desc": "",
                    "lua_type": "any"
                },
                {
                    "name": "right",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 14,
                "path": "src/x/assertEqual.lua"
            }
        },
        {
            "name": "test",
            "desc": "Creates a new test inside of the current scope.\n\n\n```lua\ntest(\"1 == 1\", function()\n\tassert(1 == 1)\nend)\n```",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "(context: {}) -> ()"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 19,
                "path": "src/x/init.lua"
            }
        },
        {
            "name": "testFOCUS",
            "desc": "Creates a new test inside of the current scope. If any test is focused, only focused tests will run.\n\n\n```lua\ntestFOCUS(\"1 == 1\", function()\n\tassert(1 == 1)\nend)\n```",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "(context: {}) -> ()"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 35,
                "path": "src/x/init.lua"
            }
        },
        {
            "name": "testSKIP",
            "desc": "Creates a new test inside of the current scope that will be skipped.\n\n\n```lua\ntestSKIP(\"skip\", function()\n\tprint(\"this will not print\")\nend)\n```",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "(context: {}) -> ()"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 51,
                "path": "src/x/init.lua"
            }
        },
        {
            "name": "beforeEach",
            "desc": "Runs `callback` before each test inside its scope runs. It's passed a `context` table unique to that test.\n`context` can be used to share setup code across tests.\n\n\n```lua\nbeforeEach(function(context)\n\tcontext.maid = Maid.new()\nend)\n\ntest(function(context)\n\tassert(context.maid:isEmpty())\nend)\n```",
            "params": [
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "(context: {}) -> ()"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 71,
                "path": "src/x/init.lua"
            }
        },
        {
            "name": "afterEach",
            "desc": "Runs `callback` after each test inside its scope runs. It's passed a `context` table which can be used to cleanup\nstate unique to the test.\n\n\n```lua\nafterEach(function(context)\n\tcontext.object:destroy()\nend)\n```",
            "params": [
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "(context: {}) -> ()"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 87,
                "path": "src/x/init.lua"
            }
        },
        {
            "name": "nested",
            "desc": "Creates a nested scope for tests. It can be used to group tests that are testing similar things.\n\n\n```lua\nnested(\"nested\", function()\n\t-- This `beforeEach` will only affect tests inside of this nested scope.\n\tbeforeEach(function() end)\n\n\ttest(\"nested test\", function() end)\nend)\n```",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "() -> ()"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 106,
                "path": "src/x/init.lua"
            }
        },
        {
            "name": "shouldThrow",
            "desc": "Throws if the callback doesn't error or if the error does not contain `substring`.\n\n```lua\n-- This will not throw because the callback errors with a string containing \"needle\"\nshouldThrow(function()\n\terror(\"haystick with a needle\")\nend, \"needle\")\n```",
            "params": [
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "() -> ()"
                },
                {
                    "name": "substring",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 16,
                "path": "src/x/shouldThrow.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "x",
    "desc": "This class is passed into test modules.",
    "source": {
        "line": 112,
        "path": "src/x/init.lua"
    }
}