kshitij
kshitij

Reputation: 624

Additional dependencies on other services in angular unit test

describe('Controller:explorerCtrl', function() {
'use strict';
var explorerCtrl;
var explorerService;
var listService;
var scope;
var $httpBackend;
var aggregatedPods_;
var $state;
var $mdDialog;
var StateService;
var spy;

beforeEach(module(
'ui.router', explorer, kpi,
list));

 beforeEach(inject(function(
_$controller_, _$httpBackend_, _$rootScope_, _explorerService_, _$state_,
_listService_) {
scope = _$rootScope_.$new();
listService = _listService_;
aggregatedPods_ = {};
explorerService = _explorerService_;
spy = jasmine.createSpy();
StateService = {go: spy};
$httpBackend = _$httpBackend_;
$state = _$state_;
explorerCtrl =
_$controller_('explorerCtrl', {$scope: scope, $state: StateService});


}));
});

Hi, I am trying to write angular test cases for my separate module. Unfortunately, my list module above breaks down my test cases. I have common service listServices($mdDialog) and using directly in my list controller(list module). When I am trying to run my angular unit test then I got an error unknown $provider $mdDialogProvider <- $mdDialog <- listService .What should I do in this case ?

I already tried to inject $mdDialog into $inject function. Still got same error. Please correct me where I am doing wrong.

 beforeEach(inject(function(
  _$controller_, _$httpBackend_, _$rootScope_, _explorerService_, _$state_,
  _listService_ _$mdDialog_);

Upvotes: 3

Views: 232

Answers (1)

Vasanth
Vasanth

Reputation: 210

I think you need to inject the $mdDialog using $provide and in your controller you need to inject $mdDialog like this:

beforeEach(function() {
    module(function(_$provide_) {
        _$provide_.service('$mdDialog', function() {});
    });
});

beforeEach(inject(function(
    _$controller_, 
    _$httpBackend_, 
    _$rootScope_, 
    _explorerService_, 
    _$state_, 
    _listService_,
    _$mdDialog_) {

     // ...
}));

Upvotes: 4

Related Questions