0
rota gidermek, yer değiştirme, birim testleri, karma-yasemin, değilseniz sizeangularjs i bütün eylemler bir rota kararlılık yazdım açısal olarak
$routeProvider.when('/home', {
resolve: {
Authenticated: function($location, AuthAuthenticator, AuthIdentity) {
return new Promise(function(resolve, reject) {
AuthAuthenticator.init().then(
function(success) {
if (!AuthAuthenticator.isAuthenticated()) {
$location.path("/login");
resolve(true);
}
resolve(false);
},
function(error) {
reject(error);
}
);
});
}
}
});
kaydedilir veya değil Hava kontrol etmek giriş yaptık giriş sayfasına doğru yönlendiriyoruz. Şimdi bunu karma-yasemin birim testimizde test etmek istiyorum. Ancak testi yazarsam, location.path değişmez.
describe('LoginController', function() {
beforeEach(module('dcApp'));
beforeEach(function() {
var _authenticated = false;
AuthAuthenticatorMock = {
isAuthenticated: function() {
return _authenticated
},
setAuthenticated: function(authenticated) {
_authenticated = authenticated;
},
};
module(function($provide) {
$provide.value('AuthAuthenticator', AuthAuthenticatorMock);
});
});
var $controller;
beforeEach(inject(function(_$route_, _$location_, _$controller_, _AuthAuthenticator_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$route = _$route_;
$location = _$location_;
$controller = _$controller_;
AuthAuthenticator = _AuthAuthenticator_;
}));
describe('Controller activation', function() {
it ('redirects to login if user is not yet logged in', function() {
AuthAuthenticator.setAuthenticated(false);
var $scope = {};
var controller = $controller('HomeController', { $scope: $scope });
expect($location.path()).toBe('/login');
});
});
});
Ama sonucudur:
PhantomJS 2.1.1 (Linux 0.0.0) HomeController Controller activation redirects to login if user is not yet logged in FAILED
Expected '' to be '/login'.
Şimdi ben casusu bazı belgeleri gördüm, ama bu konum değişikliği için nasıl kontrol edileceğini alamadım.