angularjs - How to inject a service to jasmine -


i have following test case meetingctrlspec.js

describe('viewmeetingctrl', function () {         var $rootscope, scope, $controller   ;         beforeeach(angular.mock.module('myapp'));         beforeeach(inject(function ($rootscope, $controller  ) {             scope = $rootscope.$new();             $controller('viewmeetingctrl', {             $scope: scope,            });          }));          it('should change greeting value if name value changed', function () {             //some assertion         });     }); 

viewmeetingctrl.js

(function () {     'use strict';     angular.module('myapp').controller('viewmeetingctrl', viewmeetingctrl);      viewmeetingctrl.$inject = ['$scope', '$state', '$http', '$translate', 'notificationservice', 'meetingservice', '$modal', 'meeting', 'attachmentservice'];      function viewmeetingctrl($scope, $state, $http, $translate, notificationservice, meetingservice, $modal, meeting, attachmentservice) {         $scope.meeting = meeting;                             //more code goes here     } })(); 

this meeting comes app.routes.js file

.state('company.meeting', {                 abstract: true,                 url: '/meetings/:meetingid',                 template: '<ui-view/>',                 resolve: {                     meeting: function(meetingservice, $stateparams){                         return meetingservice                                 .getmeeting($stateparams.meetingid)                                 .then(function(response){                                     return response.data;                                 });                     }                 },             }) 

my problem regarding injection of meeting in ctrl . not sure how inject in test case. did following .

describe('viewmeetingctrl', function () {             var $rootscope, scope, $controller , meeting   ;             beforeeach(angular.mock.module('myapp'));             beforeeach(inject(function ($rootscope, $controller , meeting     ) {                 scope = $rootscope.$new();                 $controller('viewmeetingctrl', {                 $scope: scope,                 meeting : meeting                   });              }));              it('should change greeting value if name value changed', function () {                 //some assertion             });         }); 

... , got error error: [$injector:unpr] unknown provider: meetingprovider <- meeting

how inject meeting dependency test case . ?

meeting not service, object injected when route resolve. in test case should explicitly create meeting dummy object.

 beforeeach(inject(function ($rootscope, $controller,$q ) {                 scope = $rootscope.$new();                  $controller('viewmeetingctrl', {                 $scope: scope,                 meeting : {}  //your custom object                });              }));  

remember testing controller in test not route resolution injection.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -