Skip to content

Instantly share code, notes, and snippets.

@dgieselaar
Created September 7, 2015 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgieselaar/d722633cd77164c4e02f to your computer and use it in GitHub Desktop.
Save dgieselaar/d722633cd77164c4e02f to your computer and use it in GitHub Desktop.
var listeners = [],
$window;
beforeEach(function ( ) {
var fn;
if(!$window) {
$window = angular.injector([ 'ng' ]).get('$window');
fn = $window.addEventListener;
$window.addEventListener = function ( ) {
listeners.push({ type: arguments[0], fn: arguments[1] });
return fn.apply($window, arguments);
};
}
});
afterEach(function ( ) {
var listener;
while(listeners.length) {
listener = listeners.shift();
$window.removeEventListener(listener.type, listener.fn);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment