I'm trying ti do a unit test for my AngularJs app, using Chutzpah in VS2013.
Let's say I have this factory:
myAppModule.factory('MyService',function(){
var fact = {};
fact.myFunction = function(){
return "Hello";
};
});
I wrote the unit test for it like this:
describe("TestService-Test", function () {
var service;
beforeEach(function () {
module('myApp');
inject(function ($injector) {
service = $injector.get('MyService');
});
});
This works fine, but if I added to the same service just one dependency (or more):
myAppModule.factory('MyService',function($scope){ ... etc the same
Even if I didn't use $scope, this will throw an exception when run the test in VS2013 using Chutzpah, and the exception says:
Result Message: Error: [$injector:unpr] ... etc
As I understood from this error it's about not be able to identify the service I'm asking for.
I need to be able to inject some dependencies in the service creation, but how to do it ?
If I did the same with the controller It'll work like a charm because, it has a clear way to inject the dependencies while creating the controller using the service $controller
.
PS:
At the top of test js file I'm including those references:
/// <reference path="../js/angular.min.js" />
/// <reference path="../js/angular-mocks.js" />
/// <reference path="../js/myAppFile.js" />
/// <reference path="../js/myServiceFile.js" />