我需要你的帮助。 我收到了错误消息: 错误:没有待处理的待处理请求!
这是我的工厂:
angular.module('myapp')
.factory('WebDB', function ($http, LocalDB) {
function lastChangeParameter(resource) {
return new Promise(function (resolve, reject) {
LocalDB.getLastChange(resource).then(function (time) {
resolve("last_change=" + time);
});
});
}
return {
getBuildings: function () {
return lastChangeParameter("buildings").then(function (lastChange) {
return get(sourceDB + "buildings" + "?" + lastChange);
});
}};
});
并测试:
describe('Testing webdb module...', function () {
var WebDB;
var httpBackend;
var mockedLocalDB;
var $rootScope;
beforeEach(function () {
module("myapp");
mockedLocalDB = {
getLastChange: function (resource) {
return new Promise(function (resolve, reject) {
resolve(0);
});
}
};
module(function ($provide) {
$provide.value('LocalDB', mockedLocalDB);
});
inject(function ($injector) {
WebDB = $injector.get("WebDB");
httpBackend = $injector.get("$httpBackend");
$rootScope = $injector.get("$rootScope");
});
});
afterEach(function () {
httpBackend.verifyNoOutstandingExpectation();
httpBackend.verifyNoOutstandingRequest();
});
describe("WebDB", function () {
describe("getBuildings", function () {
it("should download updated buildings", function () {
var respondData = {};
httpBackend.expectGET('http://server.com/builgings').respond(200, respondData);
WebDB.getBuildings().then(function (buildings) {
result = buildings;
});
$rootScope.$digest();
httpBackend.flush();
expect(result).toEqual(respondData);
});
});
我认为这是因为在获取请求之前我正在调用一些db函数,这是一个承诺。如果没有那个调用它可以完美地工作,但我真的需要在获取请求之前向本地DB请求lastChange值。 我的测试或工厂出了什么问题? 谢谢你的帮助!