Using Protractor with $ httpBackend is correct

I read about how Protractor works, I wrote some E2E tests and I am still embarrassed about using it with the service $httpBackend

and I think it is possible that I am missing an important part of the image.

In order to make HTTP calls, I will need to use the $httpBackend

service
provided in the Angular ngMockE2E

module. For this module to be included in the application under test, I need to configure it when I boot my main module depending on its dependency:

angular.module('myApp', ['ngMockE2E', 'bunch-of-other-dependencies']) 

      

This effectively means that I need to have separate initialization for my E2E tests from production initialization. This also means that I need to have a separate one index.html

.

Maintaining two additional files "almost" identical to the roots seems cumbersome. Moreover, the separate definition of index and unit means that the tests will be tested on several different applications than production, which for me seems to contradict its purpose.

Am I understanding the riddle correctly or am I missing something? Are there any better solutions for running unexposed E2E tests with Angular? Or maybe at least there are some workarounds to minimize the impact of service anxiety if they really aren't possible?

+3


source to share


1 answer


I found a workaround that might work for you.

I define my application in a html page and add base module and ngMockE2E as dependencies. In my build dist, I added grunt-processhtml, which removes everything between build: remove comments.

In the grunt service, I did not include grunt-processhtml so that it works with $ httpBackend. Similarly, I add my httpBackend expectations, which are removed in the dist build.



angular.module('myApp', [
    'myAppModule'
 <!-- build:remove -->
 <!-- including ngMock to test locally, but build remove wil make sure it not in the dist -->
    , 'ngMockE2E'
    <!-- /build -->
    '
]) ;

      

It's a little setup work, but once set up, it gives a lot of flexibility.

+2


source







All Articles