Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit dd8efbf

Browse files
author
Matt Lewis
committed
fix($window): allow $window to be mocked in unit tests
Fixes #15685
1 parent 79c4a71 commit dd8efbf

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ng/jsonpCallbacks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
var $jsonpCallbacksProvider = /** @this */ function() {
1313
this.$get = ['$window', function($window) {
14-
var callbacks = $window.angular.callbacks;
14+
var callbacks = $window.angular ? $window.angular.callbacks : {};
1515
var callbackMap = {};
1616

1717
function createCallback(callbackId) {

test/ng/jsonpCallbacksSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,17 @@ describe('$jsonpCallbacks', function() {
7979
expect($window.angular.callbacks._0).toBeUndefined();
8080
}));
8181
});
82+
83+
describe('$window mocked', function() {
84+
85+
beforeEach(module(function($provide) {
86+
$provide.value('$window', {});
87+
}));
88+
89+
it('should not throw when $window.angular does not exist', inject(function($injector) {
90+
expect(function() {
91+
$injector.get('$jsonpCallbacks');
92+
}).not.toThrow();
93+
}));
94+
});
8295
});

0 commit comments

Comments
 (0)