0

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" />
Dabbas
  • 3,112
  • 7
  • 42
  • 75
  • Sorry it's not an issue, as I saw that I can't even inject $scope in factory because it's not a provider. I tried it with $http and $rootScope providers and it did work. – Dabbas Sep 11 '15 at 12:22

2 Answers2

0

I think this is the same question that was cross posted on the Chutzpah github page. The resolution there was posted by the same original poster:

Sorry it's not an issue, as I saw that I can't even inject $scope in factory because it's not a provider. I tried it with $http and $rootScope providers and it did work.

Matthew Manela
  • 16,572
  • 3
  • 64
  • 66
  • yes right and I posted a comment under the question to clarify the solution, I'll post it as an answer too – Dabbas Sep 15 '15 at 08:56
0

Sorry it's not an issue, as I saw that I can't even inject $scope in factory because it's not a provider. I tried it with $http and $rootScope providers and it did work

Dabbas
  • 3,112
  • 7
  • 42
  • 75