我正在以下列方式进行休息呼叫
updateOperation = function (UUID) {
var deferred = $q.defer(),
restApiPath = restApiBasePath + UUID + "/_update",
updateSuccess = function () {
deferred.resolve();
},
updateFailure = function (errorObj) {
deferred.reject(errorObj);
};
xyzService.invokeREST("PUT", restApiPath, updateSuccess , updateFailure ,true);
return deferred.promise;
}
我的测试用例看起来像这样
it("should call update & resolve promise when http response is", function() {
$httpBackend.expectPUT(getValidURL).respond(200, true);
taskService.updateOperation(UUID).then(function(status,data){
expect(status).toEqual(200);
});
$httpBackend.flush();
});
xyzService
invokeRest = function(httpMethod, serviceURL, successCB, failureCB, retainJSON, postData) {
var self = this,
requestHeaderDefaults = {
"Content-Type": "application/json;charset=UTF-8"
},
$http({
method: httpMethod,
url: serviceURL,
data: postData || {},
headers: requestHeaderDefaults
})
.success(function(data, status, headers, config) {
data = JSON.parse(data);
successCB(data);
return data;
})
.error(function(data, status, headers, config) {
failureCB(data);
return data;
});
},
我在这里得到的数据和状态都是undefined
。这里有什么我想念的吗?
答案 0 :(得分:0)
这是因为承诺已解决为deferred.resolve();
:
then
taskService.updateOperation(UUID).then(function(status,data){
...
函数有一个参数,它是已解析的值,而预期它有多个参数,这不会起作用:
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);