Skip to content

Instantly share code, notes, and snippets.

@dalemanthei
Created January 24, 2016 22:18
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 dalemanthei/5d86c083725791c84671 to your computer and use it in GitHub Desktop.
Save dalemanthei/5d86c083725791c84671 to your computer and use it in GitHub Desktop.
Decorate $window to capture and count new window open events
// override the $window.open to count usage and prevent
// new windows from opening when running karma in watch mode
beforeEach(module(function ($provide) {
newWindow = {
location: {},
focusCalled: false,
closeCount: 0,
focus: function () {
newWindow.focusCalled = true;
},
close: function () {
newWindow.closeCount += 1;
}
};
//noinspection JSValidateTypes
$provide.decorator('$window', ['$delegate',
function ($delegate) {
$delegate.openCount = 0;
$delegate.open = function () {
$delegate.openCount = $delegate.openCount + 1;
return newWindow;
};
$windowMock = $delegate;
return $delegate;
}
]);
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment