diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-04-25 11:55:03 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-04-25 11:55:03 +0100 |
commit | 265e698cd07f7ee508a741200870a3e79d47b2e7 (patch) | |
tree | a66e26b9d8cac1a99c5561b9a648acc3a8373064 /spec/util_events_spec.lua | |
parent | 557b2e8ea3be02b00da2ac09f53aa39443a2c8ab (diff) | |
download | prosody-265e698cd07f7ee508a741200870a3e79d47b2e7.tar.gz prosody-265e698cd07f7ee508a741200870a3e79d47b2e7.zip |
util.events: Add more tests (100% line coverage)
Diffstat (limited to 'spec/util_events_spec.lua')
-rw-r--r-- | spec/util_events_spec.lua | 21 |
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 () |