Skip to content

Commit

Permalink
fix: grandparents hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
dknight committed Nov 3, 2024
1 parent ba7d531 commit 9105cba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/laura/Runnable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,14 @@ end

---@param typ HookType
function Runnable:runHooks(typ)
for _, hook in ipairs(self.hooks[typ]) do
-- Maybe use grandparents, etc, go up to tree.
local hooks = {}
if #self.hooks[typ] > 0 then
hooks = self.hooks[typ]
elseif self.parent ~= nil and #self.parent.hooks[typ] > 0 then
hooks = self.parent.hooks[typ]
end
for _, hook in ipairs(hooks) do
local ok, err = pcall(hook.func)
if not ok then
self.error = {
Expand Down
10 changes: 10 additions & 0 deletions test/Hook_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ describe("before hooks", function()
it("before each should be called trice", function()
expect(beforeEachSpy).toHaveBeenCalledTimes(3)
end)

describe("inner suite", function()
it("should run hooks inner", function()
expect(beforeEachSpy).toHaveBeenCalledTimes(4)
end)

it("should run hooks inner 2", function()
expect(beforeEachSpy).toHaveBeenCalledTimes(5)
end)
end)
end)

describe("after hooks", function()
Expand Down

0 comments on commit 9105cba

Please sign in to comment.