【发布时间】:2015-12-10 23:33:17
【问题描述】:
我正在尝试使用 Jasmine 测试我的 Angular 应用程序。 我就是这样称呼它的:
$httpBackend
.expectPOST('http://localhost:3000/booking_requests.json',
{lat: 58.37, lng: 26.71})
.respond(201);
sharedProperties.setLatitude(58.37);
sharedProperties.setLongitude(26.71);
scope.submit();
$httpBackend.flush();
这是我在函数中所拥有的:
$scope.submit = function() {
console.log(sharedProperties.getLatitude());
console.log(sharedProperties.getLongitude());
console.log($scope.formdata.name);
var parameter = JSON.stringify({lng: sharedProperties.getLongitude(), lat: sharedProperties.getLatitude(),
name: $scope.formdata.name});
console.log(parameter);
$http.post('http://localhost:3000/booking_requests.json',parameter )
.then(function (response) {
$scope.sync_notification = response.data.eta;
$scope.modal.show();
PusherService.subscribe(response.data.id);
});
};
还有错误:
TypeError: 'undefined' is not an object (evaluating 'response.data.eta')
所以我必须让它忽略我从 post 方法获得的 json 内容。任何想法或评论将不胜感激。
【问题讨论】:
标签: angularjs jasmine http-post karma-jasmine