(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)
当我尝试为这种情况编写单元测试时,它总是给我$ $ undefined,Any idea什么可能出错?
Ius注入的方式如下:
beforeEach(inject(function ($q_, _testService_) {
q = $q
fmOauthAccessTokenService = _testService_;
scope = $rootScope.$new();
}));
答案 0 :(得分:1)
应该是这样的(请注意$q
周围的双下划线):
beforeEach(inject(function (_$q_, _testService_) {
q = _$q_;
fmOauthAccessTokenService = _testService_;
scope = $rootScope.$new();
}));