didjoman didjoman - 1 year ago 333
AngularJS Question

Use Jasmine to test a service with uibModal and lodash as dependencies

This is my first time using Jasmine, and I have tested my first Factory without problems.

But now, I want to test this Service:

angular.module('Questions', [])
.service('QuestionsService', function($uibModal, $log, _) {

$uibModal is from UI Bootstrap (see here) and _ is Lodash.

My Jasmine test so far is:

describe('Service: QuestionsService', function() {

var QuestionsService;

beforeEach(inject(function(_QuestionsService_) {
QuestionsService = _QuestionsService_;


And when I try it (grunt test), I get the following error:

Error: [$injector:unpr] Unknown provider: $uibModalProvider <- $uibModal <- QuestionsService

And at some point I also had:

Error: [$injector:unpr] Unknown provider: _Provider <- _ <- QuestionsService

If it can help, my Karma conf is:

module.exports = function(config) {
'use strict';
autoWatch: true,
basePath: '../',

frameworks: [

// list of files / patterns to load in the browser
files: [
// bower:js
// endbower
exclude: [
port: 8080,
browsers: [
plugins: [
singleRun: false,
colors: true,
logLevel: config.LOG_INFO,

Answer Source

The app's module was not included in the test. The refactored test for the QuestionService would be:

describe('Service: QuestionsService', function() {

    var QuestionsService;

    // The module needs to be included in the test.

    beforeEach(inject(function(_QuestionsService_) {
      QuestionsService = _QuestionsService_;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download