Software /
code /
prosody
Changeset
8761:b6e193e33145
util.events: Add more tests (100% line coverage)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 25 Apr 2018 11:55:03 +0100 |
parents | 8760:6f3c3bb768cb |
children | 8762:2f8523bf7ff2 |
files | spec/util_events_spec.lua |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_events_spec.lua Tue Apr 24 23:03:02 2018 +0100 +++ b/spec/util_events_spec.lua Wed Apr 25 11:55:03 2018 +0100 @@ -113,6 +113,12 @@ 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 @@ 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 ()