为什么我没有在Jasmine测试用例中获取状态代码?

问题描述 投票:0回答:1

我正在以下列方式休息

            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。这里有什么我想念的吗?

angularjs jasmine karma-jasmine
1个回答
0
投票

发生这种情况是因为承诺被解决为undefined

deferred.resolve();

then函数有一个参数,它是已解析的值,而它有多个参数,这不起作用:

taskService.updateOperation(UUID).then(function(status,data){
...
© www.soinside.com 2019 - 2024. All rights reserved.