Added a public flattenListeners method.

Takes an array of listener objects and returns the listener functions.
Tests now make use of flattenListeners.

This remove a lot of repetition to convert to a different format when
testing.
Added and tested the addOnceListener method.