Mocking API with httpBackend [Protractor]

I am developing a frontend app for REST API. I use Protractor for end-to-end tests when running an API. I was able to mock the API AUTHtoken response and navigate to the selected url, but the page displayed under the given url goes blank. Here's my code:

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();
});
});

      

Unfortunately, the Contractor console does not provide information on errors during page rendering.

+3


source to share


1 answer


Actually, a 200 response does not guarantee that you are authenticated. You need to pass and process the token / session header.

Also required $httpBackend.flush();

. Then the test must pass.



$httpBackend.expectGET('http://0.0.0.0:9000/#/organizations/profile');
$httpBackend.flush();

      

A more detailed description will be found in the last it (...) block in the Angular doc for $ httpBackend

-1


source







All Articles