Fix redirect during jasmine tests

Change https://review.openstack.org/#/c/200725/ added a new test
that causes browsers to redirect to the login page while running
Jasmine tests. This changes the test to inject a mock $window
object so that the code under test doesn't use the real
window.location.replace() method.

Change-Id: Ie55a56b67a6f03dd3fb578e92adb18d8e5fe0b55
Closes-Bug: #1474498
This commit is contained in:
Tyr Johanson 2015-07-14 16:38:27 -06:00 committed by Dan Siwiec
parent 1791ae066e
commit f21bccda3b
1 changed files with 15 additions and 2 deletions

View File

@ -18,12 +18,25 @@
'use strict';
describe('horizon.framework', function() {
beforeEach(module('horizon.framework'));
// Mock $window. This allows our mock $window to be used
// by horizon.framework's config block instead of the
// real $window service. This prevents accidentally redirecting
// the browser during testing.
beforeEach(module('horizon.framework', function($windowProvider) {
var window = {
location: {
replace: jasmine.createSpy()
}
};
$windowProvider.$get = function() {
return window;
};
}));
describe('when unauthorized', function() {
it('should redirect to /auth/logout', inject(function($http, $httpBackend, $window) {
spyOn($window.location, 'replace');
$httpBackend.when('GET', '/api').respond(401, '');
$http.get('/api').error(function() {