# HG changeset patch # User Matthew Wild # Date 1524653703 -3600 # Node ID b6e193e331457e49afb09890426a3fd89b6468a8 # Parent 6f3c3bb768cbfbffc12d3583767e14594e645bbf util.events: Add more tests (100% line coverage) diff -r 6f3c3bb768cb -r b6e193e33145 spec/util_events_spec.lua --- 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 ()