{"id":17657977,"url":"https://github.com/3rd/testing.nvim","last_synced_at":"2026-01-03T17:45:21.621Z","repository":{"id":238217261,"uuid":"796116843","full_name":"3rd/testing.nvim","owner":"3rd","description":"Minimal testing toolkit for Neovim.","archived":false,"fork":false,"pushed_at":"2024-05-12T21:22:10.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T03:38:12.055Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/3rd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-05T01:26:04.000Z","updated_at":"2024-05-12T21:22:13.000Z","dependencies_parsed_at":"2024-05-12T22:26:08.984Z","dependency_job_id":null,"html_url":"https://github.com/3rd/testing.nvim","commit_stats":null,"previous_names":["3rd/testing.nvim"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Ftesting.nvim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Ftesting.nvim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Ftesting.nvim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Ftesting.nvim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3rd","download_url":"https://codeload.github.com/3rd/testing.nvim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244327899,"owners_count":20435516,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-23T14:43:50.302Z","updated_at":"2026-01-03T17:45:21.566Z","avatar_url":"https://github.com/3rd.png","language":"Lua","readme":"# testing.nvim\n\n**testing.nvim** is a minimal testing solution for Lua code running in Neovim.\n\n![screenshot](https://github.com/3rd/testing.nvim/assets/59587503/3e4bc034-2376-40d5-bbe0-baa6686b71e7)\n\n### Setup\n\n**Non-interactive setup**\n\nTo set this up for non-interactive testing with Neovim (`:help -l`):\n\n1. Create a lua file that bootstraps your testing context by:\n   - Adding your plugin and `testing.nvim` to the `rtp`\n   - Calling `require(\"testing\").setup(...)`\n2. Launch Neovim with the bootstrap file loaded as a session script and the test file.\n   - `nvim -S ./bootstrap.lua -l ./lua/your_spec.lua`\n\n**Setup examples**\n\n- [time-tracker.nvim](https://github.com/3rd/time-tracker.nvim)\n\n### Configuration\n\nConfiguration schema and default values:\n\n```lua\n---@class UserConfig\n---@field exit_on_first_fail? boolean\n---@field file_patterns? table\u003cstring\u003e\n---@field inject_globals? boolean\n---@field output_file? string|nil\n---@field quiet? boolean\n---@field reporter? Reporter\n\nlocal default_config = {\n  exit_on_first_fail = false,\n  file_patterns = { \"**/*_spec.lua\" },\n  inject_globals = true,\n  output_file = nil,\n  quiet = false,\n}\n```\n\n### Usage\n\nThis is what the plugin exports:\n\n- `setup(config?)` - setup function, needs to be called to set globals\n- `describe(\"...\", fn)` - declare a test group / suite\n- `it(\"...\", fn)` - declare a test inside a test group\n- `expect(actual).toSomething(...)` - make an assertion\n- `before_each(fn)`, `after_each(fn)` - hooks\n- `spy(target, \"key\")` - spy \u0026 mock functions\n\nIf `inject_globals == true`, the following exports become globals: `describe`, `it`, `expect`, `before_each`, `after_each`\n\nCheck out these files for the implementation:\n\n- [testing/core/describe.lua](lua/testing/core/describe.lua)\n- [testing/core/it.lua](lua/testing/core/it.lua)\n- [testing/core/expect.lua](lua/testing/core/expect.lua)\n\n**Assertions**\n\n- `expect(actual).toBe(expected)` - `actual == expected`\n- `expect(actual).toEqual(expected)` - `vim.deep_equal(actual, expected)`\n- `expect(actual).toContain(expected)` - `vim.tbl_contains(actual, expected)`\n- `expect(actual).toMatch(pattern)` - `string.find(actual, expected)`\n- `expect(actual).toThrow(message?)`- expect `actual()` to throw (w/ optional error)\n- `expect(spy).toHaveBeenCalled()`\n- `expect(spy).toHaveBeenCalledTimes(n)`\n- `expect(spy).toHaveBeenCalledWith(...)`\n- `expect(spy).toHaveBeenLastCalledWith(...)`\n- `expect(spy).toHaveBeenNthCalledWith(n, ...)`\n\n**Negated assertions**\n\nAll the assertions have negated variants under `expect(actual).n`:\n\n- `expect(actual).n.toBe(expected)`\n- ...\n\n**Examples**\n\n```lua\ndescribe(\"expect\", function()\n  it(\"asserts .toEqual(value)\", function()\n    expect(1).toEqual(1)\n    expect(vim).toEqual(vim)\n    expect({}).toEqual({})\n    expect({ a = 1 }).toEqual({ a = 1 })\n  end)\n\n  it(\"asserts .n.toEqual(value)\", function()\n    expect(1).n.toEqual(2)\n    expect(vim).n.toEqual(vim.api)\n    expect({}).n.toEqual({ 1 })\n    expect({ a = 1 }).n.toEqual({ a = 2 })\n  end)\nend)\n```\n\n**Spies/mocks**\n\nTo spy \u0026 mock a function, use the exported `.spy(target, \"key\")` helper.\n\\\nIt returns a `Spy` object on which you can call:\n\n- `spy.clear()` - to clear the stored calls from memory\n- `spy.reset()` - to clear the mocked implementation / return value and internal state\n- `spy.destroy()` - to kill the spy and restore the original function\n- `spy.mockImplementation(fn)`\n- `spy.mockImplementationOnce(fn)`\n- `spy.mockReturnValue(value)`\n- `spy.mockReturnValueOnce(value)`\n\n```lua\nlocal t = require(\"testing\")\n\ndescribe(\"milkshake\", function()\n  it(\"brings all the boys to the yard\", function()\n    local target = {\n      bring_boys = function()\n        return false\n      end,\n    }\n    local spy = t.spy(target, \"bring_boys\")\n\n    expect(target.bring_boys()).toBe(false)\n    expect(spy).toHaveBeenCalled()\n\n    spy.mockReturnValueOnce(true)\n    expect(target.bring_boys()).toBe(true)\n    expect(target.bring_boys()).toBe(false)\n\n    expect(spy).toHaveBeenCalledTimes(3)\n  end)\nend)\n```\n\n### WIP\n\n- test runner\n- child process wrapping (rpc)\n- GH action\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3rd%2Ftesting.nvim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3rd%2Ftesting.nvim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3rd%2Ftesting.nvim/lists"}