Created
January 24, 2016 22:18
-
-
Save dalemanthei/5d86c083725791c84671 to your computer and use it in GitHub Desktop.
Decorate $window to capture and count new window open events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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