aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-04-25 11:55:03 +0100
committerMatthew Wild <mwild1@gmail.com>2018-04-25 11:55:03 +0100
commita606a2f7e3f990f8e99ce28ab22ef9cd6830839c (patch)
treea66e26b9d8cac1a99c5561b9a648acc3a8373064
parent3f5ce6beff3e12aed35d0a3324102c5590ffa018 (diff)
downloadprosody-a606a2f7e3f990f8e99ce28ab22ef9cd6830839c.tar.gz
prosody-a606a2f7e3f990f8e99ce28ab22ef9cd6830839c.zip
util.events: Add more tests (100% line coverage)
-rw-r--r--spec/util_events_spec.lua21
1 files changed, 21 insertions, 0 deletions
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 ()