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

fix($window): allow $window to be mocked in unit tests #15686

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ng/jsonpCallbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* how they vary compared to the requested url.
*/
var $jsonpCallbacksProvider = /** @this */ function() {
this.$get = ['$window', function($window) {
var callbacks = $window.angular.callbacks;
this.$get = function() {
var callbacks = angular.callbacks;
var callbackMap = {};

function createCallback(callbackId) {
Expand Down Expand Up @@ -78,5 +78,5 @@ var $jsonpCallbacksProvider = /** @this */ function() {
delete callbackMap[callbackPath];
}
};
}];
};
};
13 changes: 13 additions & 0 deletions test/ng/jsonpCallbacksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,17 @@ describe('$jsonpCallbacks', function() {
expect($window.angular.callbacks._0).toBeUndefined();
}));
});

describe('$window mocked', function() {

beforeEach(module(function($provide) {
$provide.value('$window', {});
}));

it('should not throw when $window.angular does not exist', inject(function($injector) {
expect(function() {
$injector.get('$jsonpCallbacks');
}).not.toThrow();
}));
});
});