使用httpBackend和Protractor模拟API

时间:2015-06-19 10:33:20

标签: angularjs protractor angularjs-e2e ngmocke2e

我正在尝试正确模拟我的API(如问题Mocking API with httpBackend [Protractor]中所示)。我正在导航到特定的网址 - “http://0.0.0.0:9000/#/organizations/profile”。网址请求特定视图,如下所示:

Error: Unexpected request: GET vcs/common/layouts/main/view.html
No more request expected
at $httpBackend (angular-mocks.js:1211)
at sendReq (angular.js:9667)
at serverRequest (angular.js:9383)
at processQueue (angular.js:13248)
at angular.js:13264
at Scope.$eval (angular.js:14466)
at Scope.$digest (angular.js:14282)
at Scope.$apply (angular.js:14571)
at bootstrapApply (angular.js:1455)
at Object.invoke (angular.js:4203)

我无法理解'whenPOST(url,[data],[headers]);'方法有效。如何在我当前的代码中正确使用它?这是我的代码:

describe('e2e tests', function() {

it('FO tests', function() {

browser.addMockModule('WebClientApp', function() {
console.log('test');
angular.module('WebClientApp', ['ngMockE2E'])
.run(function($httpBackend) {
console.log('test2');

$httpBackend.whenPOST('http://0.0.0.0:9000/api/organizations').respond(200);
$httpBackend.whenPOST('/api/auth/get_resource_by_token').respond(200);
$httpBackend.whenGET('/api/auth/current_resource').respond(200);
$httpBackend.whenGET(/.*/).respond(200);
 });

});
browser.getRegisteredMockModules();

browser.get('http://0.0.0.0:9000/#/organizations/profile');

browser.pause();
});
});

0 个答案:

没有答案