I'm trying to test something around $window.history.back()
, but I'm not seeing the expected behavior.
Here's my service logic:
angular
.module('navigation.service', [])
.factory('navigationService', navigationService);
navigationService.$inject = ['$window', '$location'];
function navigationService($window, $location) {
var service = {};
service.back = back;
function back() {
$window.history.back();
}
return service;
}
And here's my test logic:
describe('navigation.service', function() {
var window,
location,
navigationService;
beforeEach(function() {
module('navigation.service');
inject(function(_navigationService_, _$window_, _$location_) {
navigationService = _navigationService_;
window = _$window_;
location = _$location_;
// defaulting to the root path '/'
location.path('/');
});
});
it('can go back', function() {
expect(location.path()).toEqual('/'); // '/'
location.path('/next');
expect(location.path()).toEqual('/next'); // '/next'
navigationService.back();
expect(location.path()).toEqual('/'); // '/next' ???
});
});
I've made comments inline to show what's happening, but the end result is that the final location.path()
isn't reflecting the triggering of $window.history.back()
and instead holds the previous value. Any ideas why this is the case? I've been going at this for a while now and I'm stumped.
Aucun commentaire:
Enregistrer un commentaire