From 265e698cd07f7ee508a741200870a3e79d47b2e7 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 25 Apr 2018 11:55:03 +0100 Subject: util.events: Add more tests (100% line coverage) --- spec/util_events_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/util_events_spec.lua b/spec/util_events_spec.lua index 82b30311..fee60f8f 100644 --- a/spec/util_events_spec.lua +++ b/spec/util_events_spec.lua @@ -113,6 +113,12 @@ describe("util.events", function () pending("should support adding handlers within an event handler") pending("should support removing handlers within an event handler") + it("should support getting the current handlers for an event", function () + e.add_handler("myevent", h); + local handlers = e.get_handlers("myevent"); + assert.equal(h, handlers[1]); + end); + describe("wrappers", function () local w before_each(function () @@ -156,6 +162,21 @@ describe("util.events", function () assert.spy(w2).was_called(2); assert.spy(h).was_called(2); end); + + it("should support a mix of global and event wrappers", function () + local w2 = spy.new(function (handlers, event_name, event_data) + return handlers(event_name, event_data); + end); + e.add_wrapper(false, w); + e.add_handler("myevent", h); + e.add_wrapper("myevent", w2); + e.fire_event("myevent", "abc"); + e.remove_wrapper(false, w); + e.fire_event("myevent", "abc"); + assert.spy(w).was_called(1); + assert.spy(w2).was_called(2); + assert.spy(h).was_called(2); + end); end); describe("global wrappers", function () -- cgit v1.2.3