angularjs - Mocking API with httpBackend [Protractor] -
i'm developing frontend app rest api. i'm using protractor end-to-end tests api mocked out. able mock authtoken api response , navigate chosen url, page displayed under destined url renders empty. here's 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(); }); });
sadly, protractor console not provide information errors during page render.
actually, response status 200 not ensure have authenticated. need pass , handle token/session header.
also $httpbackend.flush();
needed. test should pass.
$httpbackend.expectget('http://0.0.0.0:9000/#/organizations/profile'); $httpbackend.flush();
more explanation found on last it(...) block in angular doc $httpbackend
Comments
Post a Comment