twitter/flight-jasmine — pull request #8 by scottrabin (2013-05-18 20:22:09+00:00)
Title: Clean up event spy data and detach handlers after each spec

Multiple calls to `spyOnEvent` where the selector/event pair create the
same hash will share event data between the spies. Additionally, event
handlers bound for these spies are never detached, so subsequent specs
can cause previously-bound spies to fire again. This does not affect the
most recent call, but does affect the call count; event data is stored
multiple times, once for each spy bound.

Binding spies now stores the "selector" (or possibly HTMLElement) along
with the event name to correctly detach event spy handlers via
`jasmine.flight.events.cleanUp()`, and registers this function to run
after each spec.

Reproduction steps:

```javascript
describe("someComponent", function() {
it("should listen for an arbitrary event", function() {
var innocuousSpy = spyOnEvent(document, 'event');
$(document).trigger('event');
expect(innocuousSpy.callCount).toBe(1);
});
it("should do something else with that event, too", function() {
var misbehavingSpy = spyOnEvent(document, 'event');
$(document).trigger('event');
expect(misbehavingSpy.callCount).toBe(1); // fails; callCount is 2
});
});
```

Fiddle: http://jsfiddle.net/scottrabin/tLEzf/1/