Skip to content

Commit

Permalink
refactor(stateSpec): add spy on .replace method
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed May 27, 2014
1 parent d842dfc commit 3723b29
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}));
});

Expand Down

0 comments on commit 3723b29

Please sign in to comment.