- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
测试我的 REST 服务时,我收到以下错误消息:
Error: [$resource:badcfg] query http://errors.angularjs.org/1.4.6/$resource/badcfg?p0=array&p1=object&p2=GET&p3=http%3A%2F%2Flocalhost%3A63831%2Fapi%2Fnames in http://localhost:60694/js/angular.js (line 68)
我不知道如何解决这个问题。该应用程序是否可能与 WebApi 一样位于另一个本地主机端口中?
下面的代码显示了单元测试:
describe('Test', function () {
var $httpBackend, $rootScope, crudService, baseUrl, respValue;
beforeEach(function () {
module('testApp');
inject(function (_$httpBackend_, _$rootScope_, _CrudService_, _baseUrl_) {
$httpBackend = _$httpBackend_;
$rootScope = _$rootScope_;
crudService = _CrudService_;
baseUrl = _baseUrl_;
});
});
it('should make a request to the backend', function () {
$httpBackend.whenGET('views/home.html').respond(200);
$httpBackend.expectGET(baseUrl + '/api/names').respond(200, [{
Id: '1', fname: 'John', lname: 'Doe', age: 30, GroupId: 1
}]);
$rootScope.$digest();
crudService.getAllNames().$promise.then(function (response) {
respValue = response;
});
$httpBackend.flush();
expect(respValue).toContain([{
Id: '1', fname: 'John', lname: 'Doe', age: 30, GroupId: 1
}]);
});
<小时/>
编辑:
我尝试了下面的答案并添加了 expect()
方法,并显示了以下错误消息:
Expected [ d({ Id: '1', fname: 'John', lname: 'Doe', age: 30, GroupId: 1 }), $promise: Promise({ $$state: Object({ status: 1, pending: undefined, value: , processScheduled: false }) }), $resolved: true ] to contain [ Object({ Id: '1', fname: 'John', lname: 'Doe', age: 30, GroupId: 1 }) ].
最佳答案
很可能是这一行有问题
$httpBackend.expectGET(baseUrl + '/api/names').respond(200, {
Id: '1', fname: 'John', lname: 'Doe', age: 30, GroupId: 1
});
响应应该是一个数组,但它是一个对象。您可以将此行更改为
$httpBackend.expectGET(baseUrl + '/api/names').respond(200, [{
Id: '1', fname: 'John', lname: 'Doe', age: 30, GroupId: 1
}]);
并尝试。
关于javascript - 错误: [$resource:badcfg] query when testing a resource service with Jasmine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906603/
这是我的js代码 var MYModule = angular.module('myApp', ['ngRoute', 'myAppServices']) .directive('loadin
我有一个 API,可以根据给定的 ID 将数据返回到 AngularJS,但是,当数据以 JSON 形式返回时,AngularJS 会抛出“badcfg”错误,据我所知,这是由于返回数据,但不知道如何
我的 Angular 抛出了我 Error: [$resource:badcfg] Error in resource configuration for action query. Expected
我正在尝试将spotify api与node js和Angular js连接。每当我尝试获取特定艺术家的详细信息时,我都会收到此错误。 app.js var app = angular.module
我有一个为我发布数据的服务模块: //services.js var myServices = angular.module('myServices', ['ngResource']); myServ
我已查看此处的其他帖子,但仍无法解决我的问题。 我得到一个错误: $resource:badcfg Response does not match configured parameter 我相信这个
我是一个完整的 angular 菜鸟,只是通过了一个代码学校教程,我已经遇到了我的第一个障碍。 我收到 Error: [$resource:badcfg] Error in resource conf
我有一个旧的示例应用程序,它调用休息服务,其内容如下:此应用程序不使用 angularJS。 var listName = "Events"; // the url to use fo
如何修复错误: [$resource:badcfg] Error in resource configuration. Expected response to contain an array bu
测试我的 REST 服务时,我收到以下错误消息: Error: [$resource:badcfg] query http://errors.angularjs.org/1.4.6/$resource
我想使用 $resources 从 json 文件中获取数据,但我总是遇到该错误。但是,我可以使用 $http 来完成,因此我认为我的服务设置有问题。 这是我的 Controller : $scope
我是 MEAN 堆栈开发的新手,昨天才开始。我正在尝试通过使用链接到服务器端 Controller 的资源进行调用,从数据库中取回我的数据。但我收到以下控制台错误“错误:[$resource:badc
我正在尝试使用路由参数来过滤 REST 调用的结果,但没有得到任何返回结果,而是收到以下错误: Error: error:badcfg Response does not match configur
以下是我设置文章资源的方式: define(['services/index', 'services/Helpers'], function(services) { 'use strict';
我是一名优秀的程序员,十分优秀!