chhitij srivastava chhitij srivastava - 2 years ago 173
AngularJS Question

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;

'ui.router', explorer, kpi,

_$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});


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
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
function. Still got same error. Please correct me where I am doing wrong.

_$controller_, _$httpBackend_, _$rootScope_, _explorerService_, _$state_,
_listService_ _$mdDialog_);

Answer Source

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

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

  _$controller_, _$httpBackend_, _$rootScope_, _explorerService_, _$state_, _listService_ _$mdDialog_);

like this..

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