Skip to content

Commit 80766cd

Browse files
committed
Merge pull request #1103 from a8m/master
refactor(stateSpec): add spy on .replace method
2 parents d842dfc + 3723b29 commit 80766cd

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

test/stateSpec.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -833,35 +833,24 @@ describe('state', function () {
833833
}));
834834

835835
it('should replace browser history when "replace" enabled', inject(function ($state, $rootScope, $location, $q) {
836-
var originalReplaceFn = $location.replace, replaceWasCalled = false;
837836

838-
// @todo Replace this with a spy
839-
var decoratedReplaceFn = function() {
840-
replaceWasCalled = true;
841-
originalReplaceFn.call($location);
842-
};
843-
$location.replace = decoratedReplaceFn;
837+
spyOn($location, 'replace');
844838

845839
$state.transitionTo('about', {}, { location: 'replace' });
846840
$q.flush();
847841

848-
expect(replaceWasCalled).toEqual(true);
842+
expect($location.replace).toHaveBeenCalled();
849843
}));
850844

851845
it('should not replace history normally', inject(function ($state, $rootScope, $location, $q) {
852-
var originalReplaceFn = $location.replace, replaceWasCalled = false;
853846

854-
// @todo Replace with spy
855-
var decoratedReplaceFn = function() {
856-
replaceWasCalled = true;
857-
originalReplaceFn.call($location);
858-
};
859-
$location.replace = decoratedReplaceFn;
847+
spyOn($location, 'replace');
860848

861849
$state.transitionTo('about');
862850
$q.flush();
863851

864-
expect(replaceWasCalled).toEqual(false);
852+
expect($location.replace).not.toHaveBeenCalled();
853+
865854
}));
866855
});
867856

0 commit comments

Comments
 (0)