samedi 30 mai 2015

How to inject a service to jasmine

I have the 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 is 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 from the 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 is regarding the injection of meeting in this ctrl . I am not sure how to do inject that in my test case. I did like the 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 is changed', function () {
                //some assertion
            });
        });

... and i got this error Error: [$injector:unpr] Unknown provider: meetingProvider <- meeting

How do i inject meeting dependency to my test case . ?

Aucun commentaire:

Enregistrer un commentaire