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

Commit 5ca0de6

Browse files
Matt Lewisgkalpak
Matt Lewis
authored andcommitted
fix($jsonpCallbacks): allow $window to be mocked in unit tests
Fixes #15685 Closes #15686
1 parent 50a449f commit 5ca0de6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/ng/jsonpCallbacks.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* how they vary compared to the requested url.
1111
*/
1212
var $jsonpCallbacksProvider = /** @this */ function() {
13-
this.$get = ['$window', function($window) {
14-
var callbacks = $window.angular.callbacks;
13+
this.$get = function() {
14+
var callbacks = angular.callbacks;
1515
var callbackMap = {};
1616

1717
function createCallback(callbackId) {
@@ -78,5 +78,5 @@ var $jsonpCallbacksProvider = /** @this */ function() {
7878
delete callbackMap[callbackPath];
7979
}
8080
};
81-
}];
81+
};
8282
};

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('mocked $window', 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)