Karma + Jasmine:ajax调用真实(非模拟)响应

时间:2016-02-03 13:23:22

标签: jasmine karma-runner

我想在karma env + Jasmine中发送XmlHttpRequest时从服务器获得真实的响应。测试用例

    public List<MyLocation> displayLocation() {

               mLocation = LocationServices.FusedLocationApi
                       .getLastLocation(mGoogleApiClient);
               if (mLocation != null) {

                   double latitude = mLocation.getLatitude();
                   double longitude = mLocation.getLongitude();
                   String lastUpdateTime = DateFormat.getTimeInstance().format(new Date());

//At this point, you are calling the interface.
                   locationInterface.sendDetails(latitude,longitude,lastUpdateTime);
                   dbHelper.insertLocationDetails(longitude, latitude, lastUpdateTime);
                   locationList = dbHelper.getLocationDetails();

                   return locationList;

               } else {
                   return null;
               }

        }

但我明白了:

it('get data from server', function (done) {
    var request = new XMLHttpRequest();

    request.open('GET', 'my_working_backPoint');
    request.onload = function (resp) {
        console.log(resp);
        done();
    };
    request.send();
});

我找不到任何有用的答案。请解释我如何测试真正的ajax调用。

0 个答案:

没有答案