Skip to content

Commit

Permalink
tests(event): ensure autocommands created by plugins are triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jun 5, 2024
1 parent c17ba22 commit 1594f0c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/event_spec.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: invisible
local event = require("lz.n.handler.event")
local state = require("lz.n.state")
local loader = require("lz.n.loader")
Expand Down Expand Up @@ -77,4 +78,29 @@ describe("event", function()
itt({ event.parse("BufEnter"), event.parse("WinEnter") })
itt({ event.parse("WinEnter"), event.parse("BufEnter") })
end)
it("Plugins' event handlers should be triggered", function()
---@type LzPlugin
local plugin = {
name = "foo",
event = { event.parse("BufEnter") },
pattern = ".lua",
}
local triggered = false
local orig_load = loader._load
---@diagnostic disable-next-line: duplicate-set-field
loader._load = function(...)
orig_load(...)
vim.api.nvim_create_autocmd("BufEnter", {
callback = function()
triggered = true
end,
group = vim.api.nvim_create_augroup("foo", {}),
})
end
state.plugins[plugin.name] = plugin
event.add(plugin)
vim.api.nvim_exec_autocmds("BufEnter", {})
assert.True(triggered)
loader._load = orig_load
end)
end)

0 comments on commit 1594f0c

Please sign in to comment.