angularjs

Mocking AngularJS services in unit test

When unit testing controllers in AngularJS, there are good mechanisms in place for mocking injected services, as such: var controller; var myServiceMock = { myServiceMethod: sinon.stub() }; module('myApp'); inject(function($rootScope, $controller) { var scope = $rootScope.$new(); var controller = $controller('MyController', { $scope: scope, MyService: myServiceMock }); } } So now we've created a mock of…