Recently, I made the decision to explore testing my Angular code using Jasmine. While everything seems to work fine without specific dependencies, I encountered problems when there are dependencies involved. For instance, in our project we use controllers.js:
angular.module('myApp', ['jmdobry.angular-cache'])
.controller('MyCtrl', ['$scope', '$http', function($scope, $http) {
$scope.myName = "Wojtek";
/...
}]);
Now, I'm facing the challenge of testing this:
describe('myApp', function() {
var scope,
controller;
beforeEach(angular.mock.module('myApp'));
describe('MyCtrl', function() {
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('MyCtrl', {
'$scope': scope
});
}));
it('sets proper name', function () {
expect(scope.myName).toBe("Wojtek");
});
});
});
So, my main question is - how can I mock the 'jmdobry.angular-cache' dependency in my tests?