When triggering an event that has no callback, the for loop iterating over events fails

because we try to access events.length, and events is undefined.
Added fix + test.