3
我正在與browserify
捆綁角度服務。我使用jasmine
撰寫對這一服務,該服務等被定義測試:測試角度服務也是一個承諾
angular
.module('Client', [])
.factory('client', ['url', 'otherService', '$http', '$log', client])
function client (url, otherService, $http, $log) {
$log.debug('Creating for url %s', url)
var apiRootPromise = $http.get(url).then(function (apiRoot) {
$log.debug('Got api root %j', apiRoot)
return otherService.stuff(apiRoot.data)
})
return Object.assign(apiRootPromise, otherService)
}
下面的測試套件:
describe('test client', function() {
beforeEach(function() {
angular.mock.module('Client')
angular.mock.module(function ($provide) {
$provide.value('url', 'http://localhost:8080/')
})
})
it('should connect at startup', angular.mock.inject(function (client, $rootScope, $httpBackend) {
$rootScope.$apply()
$httpBackend.flush()
expect(client).toBeDefined()
}))
})
拋出TypeError: undefined is not a constructor
上(evaluating Object.assign(apiRootPromise, otherService)')
。我不確定這裏發生了什麼,但我最好的猜測是Angular沒有正確注入依賴服務或者沒有返回$http
的承諾。