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

Commit fffb1bd

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

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/ng/jsonpCallbacks.js

+2-2
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) {

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)