gpt4 book ai didi

javascript - AngularJS 测试 $resource - 刷新给出错误

转载 作者:行者123 更新时间:2023-12-03 10:42:07 25 4
gpt4 key购买 nike

我有一家工厂

angular.module('RepServices', [ 'ngResource' ]).factory('Rep',
function($resource) {
return $resource('rep.do', {}, {
get : {
method : 'GET',
params : {
action : "fetchRep"
},
isArray : false,
responseType : "text"
}
});
});

并创建了一个测试

describe('RepService test', function () {
var httpBackend;
var repService;
var repResponseXML = '<RepEntity><active>false</active><repCode>C326</repCode></RepEntity>';

beforeEach(module('rifApp'));

beforeEach(inject(
function ($injector) {
httpBackend = $injector.get('$httpBackend');
repService = $injector.get('Rep');// Rep is name of the factory
})
);

describe('fetchRep', function () {
it ('should call the RepServices to fetchRep', function () {
var mockData = repResponseXML;
var url = 'rep.do';

httpBackend.expectGET(url).respond(mockData);

var response =
repService.get({repCode: 'C213', subfirm: '001'},
function(httpResponse) {console.log("httpResponse: " + httpResponse);},
function(httpErrorResponse) {});

console.log(response);
console.log("Promise: ");
console.log(response.$promise);


response.$promise.then(function() {console.log("callback");}, function() {console.log("errback");}, function() {console.log("progressback"); });


httpBackend.flush()
});

});

});

调用刷新时出现错误(请参阅下面的错误)。如果我删除刷新,那么 Karma 会报告成功,但它似乎没有返回我所说的模拟数据

Error: [jqLite:nosel] Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element
http://errors.angularjs.org/1.2.21/jqLite/nosel
at JQLite (C:/Users/D532335/Projects/Affirm/Trunk/RIFWeb/WebContent/javascript/lib/angular.js:2365)
.............

最佳答案

我最终不得不包含 jquery,错误中的链接告诉我要这样做。但我仍然收到错误。确保始终按照与应用程序相同的顺序加载库依赖项。

关于javascript - AngularJS 测试 $resource - 刷新给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28728237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com