diff --git a/src/laura/Runnable.lua b/src/laura/Runnable.lua index 0e82b60..3613524 100644 --- a/src/laura/Runnable.lua +++ b/src/laura/Runnable.lua @@ -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 = { diff --git a/test/Hook_test.lua b/test/Hook_test.lua index 0570eef..6e99c1b 100644 --- a/test/Hook_test.lua +++ b/test/Hook_test.lua @@ -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()