Vishal Sakaria Vishal Sakaria - 1 year ago 71
AngularJS Question

Injecting angular js service/factory into Jasmine

I am trying to run some Jasmine Unit test on a factory I have created in Angular JS.

Here is my app.js

var app = angular.module('myApp', [

Here is the services.js

app.factory('Service', function(){
var service = {
one: function(){
return 1;
return service;

Here is the Karma conf file

files: [

And here is the test

'use strict';

(function () {

describe('myApp', function () {


it('testing the service', inject(function (Service) {


I am really stuck and don't know which way to go now :(
All the correct scripts are loaded into the browser. Also the app works in normal mode in the browser, so the Service factory is fine.

The error message say:

Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngRoute due to:
Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Answer Source

The problem is exactly what the message says: ngRoute is not available, because you haven't included that script in the your Karma config file. You need to add a line like this to the the files array:


I don't know offhand what the path is, so you may need to tweak that.