From 3723b2946231f54f1afab2c0df1856541a0d6dcf Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Wed, 28 May 2014 00:27:24 +0300 Subject: [PATCH] refactor(stateSpec): add spy on .replace method --- test/stateSpec.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/test/stateSpec.js b/test/stateSpec.js index 3d504f538..75e11f268 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -833,35 +833,24 @@ describe('state', function () { })); it('should replace browser history when "replace" enabled', inject(function ($state, $rootScope, $location, $q) { - var originalReplaceFn = $location.replace, replaceWasCalled = false; - // @todo Replace this with a spy - var decoratedReplaceFn = function() { - replaceWasCalled = true; - originalReplaceFn.call($location); - }; - $location.replace = decoratedReplaceFn; + spyOn($location, 'replace'); $state.transitionTo('about', {}, { location: 'replace' }); $q.flush(); - expect(replaceWasCalled).toEqual(true); + expect($location.replace).toHaveBeenCalled(); })); it('should not replace history normally', inject(function ($state, $rootScope, $location, $q) { - var originalReplaceFn = $location.replace, replaceWasCalled = false; - // @todo Replace with spy - var decoratedReplaceFn = function() { - replaceWasCalled = true; - originalReplaceFn.call($location); - }; - $location.replace = decoratedReplaceFn; + spyOn($location, 'replace'); $state.transitionTo('about'); $q.flush(); - expect(replaceWasCalled).toEqual(false); + expect($location.replace).not.toHaveBeenCalled(); + })); });