Add automated test for beforeunload event cleanup

Some weirdness in the tests.  Since we register for
the beforeunload event on the first time the module
was required, I create a fake for window.addEventListener
and just store the eventName and func off for later use.

This explains the tense of the test: "it added a handler for
beforeunload" since I am testing that something happened in the past.