Dreamweaver
Dreamweaver

Reputation: 1346

Unable to inject $q in service while testing the service

(function (angular) {
    'use strict';
    var testingModule= angular.module('testingModule', []); 
testingModule.factory('testService', [ '$q',
        function ($q) {
            var service = {
                    get: null
                },
                tokenDeferred = $q.defer(),

            service.getDataWithPromise = function () {

                        tokenDeferred.resolve({token: this.token, isAuthenticated: true});
                    } 
                });

                return tokenDeferred.promise;
            };
})(angular)

When I am trying to write unit test for this case it always gives me $q undefined, Any Idea what can be wrong?

Below ius the way I am injecting :

   beforeEach(inject(function ($q_, _testService_) {
    q = $q
        fmOauthAccessTokenService = _testService_;

        scope = $rootScope.$new();

    }));

Upvotes: 0

Views: 139

Answers (1)

Zakaria
Zakaria

Reputation: 15070

It should be like this (please note the double underscores surrounding the $q):

beforeEach(inject(function (_$q_, _testService_) {
    q = _$q_;
        fmOauthAccessTokenService = _testService_;

        scope = $rootScope.$new();

    }));

Upvotes: 1

Related Questions