I'm using Karma, Mocha, Sinon and Chai for my Angular unit tests and I'm trying to figure out how to mock a redirect I'm doing in my controller with $location
.
My controller does the following redirect:
$location.path('home');
I want to try and mock that redirect using spies, this is what I'm currently doing:
describe('Auth Controller', function() {
var controller;
var $location;
beforeEach(function() {
bard.appModule('app.auth');
bard.inject('$controller', '$rootScope', '$location');
});
beforeEach(function() {
$location = {
path: sinon.spy().returned('Fake location')
};
controller = $controller('authCtrl', { $scope: $rootScope, $location: $location });
});
it('should take you to the metrics page on successful login', function() {
expect($location.path).to.have.been.calledWith("Fake location");
});
});
I'm getting the following error:
TypeError: false is not a spy or a call to a spy!
I'm not sure how to go about mocking this correctly or if I'm even going about this in the right way.
Any help for unit testing experts are appreciated. Thanks in advance!