1

Il go strait to it. Im writing unit tests for Angular front end application. This is what I have so far... app.js:

var app = angular.module('app', ['dependency1', 'dependency2', 'dependency3']);

Then to create a service I have:

app.factory('myService', ['serviceDependency', function(serviceDependency) {
    ...
});

How do I create/inject myService to be tested? When I do:

beforeEach(module("app"));

Jasmine screams at me about not finding dependencies, and I dont know how to mock them. (there are more than 3, like way more. :) )

beforeEach(inject(function(myService){}));

Does not work without doing the 'module' one first. Im stuck on this for 3 days googleing watching videos and I just cant find what I need, or I cant see it. First time writing for help, so do ask any questions if you feel I missed something, and you need more info.

ktnxbye

Edit:

Custom providers are created like so:

app.config(['customProvider', function(customProvider){
...
}]);

any suggestions on how to mock this?

ktnxbye
Vodonik
  • 21
  • 5
  • please check: http://stackoverflow.com/questions/14773269/injecting-a-mock-into-an-angularjs-service/18756347#18756347 – Veikko Karsikko Nov 27 '14 at 10:45
  • @vepasto Thanks for suggestion, but it did not help me. I have no problem with dependency of myService, but with dependencies of my app module. And using the code from the answer you provided, modified to mock "app" dependencies does not work. – Vodonik Nov 27 '14 at 11:13
  • Ok, solved the problem of mocking the dependencies. I created a separate file with mock module declarations and that worked, but I dont really like that solution. I have a felling that it could be better solved. But it will work for now. Next problem is with custom providers. I have a few in following format: I will edit the original question, because of code. – Vodonik Nov 28 '14 at 08:25

1 Answers1

1

Well, I've 'solved' it! What I did is I included all dependencies required by the app in the test project and now it runs fine. But I don't quite like that solution. I would like it more if I could some how mock all those dependencies. I will still try to mock them and if I'm successful I will post here for all to see. Also I would appreciate any help from all :)

ktnxbye
Vodonik
  • 21
  • 5