我有一個角度應用程序,在初始化時,請求一些http請求。多個意外請求:GET
我已經建立了一個試驗,預計第一批請求,第二,
describe("MyController--", function() {
var controller, scope, $httpBackend, myFactory;
var iResponse = {
table: 'red',
price: '1.99'
};
beforeEach(angular.mock.module('myApp'));
beforeEach(inject(function (_$controller_, _$rootScope_, _$httpBackend_, _myFactory_) {
scope = _$rootScope_.$new();
$httpBackend = _$httpBackend_;
$httpBackend.expectGET("/app/shopping/cart/layout.html").respond({});
$httpBackend.expectGET("/app/rest/products").respond(iResponse);
myFactory = _myFactory_;
spyOn(myFactory, 'getData').and.callThrough();
controller = _$controller_('MainController', {$scope: scope});
scope.$apply();
$httpBackend.flush();
}));
it('should verify that the controller exists ', function() {
expect(controller).toBeDefined();
});
通過上述,我把看到的錯誤:
Error: Unexpected request: GET /app/rest/products
Information: Expected GET /app/shopping/cart/layout.html
任何想法我是什麼失蹤?
是它使得兩次調用API?如果是這樣,你需要對每個人的呼叫有一個期望。如果你不想爲每一個ca做一個期望 – danday74