Mocking rest calls in functional e2e protractor tests in angular 4 project

9.2k views Asked by At

We have a huge project and we have written a lot of test cases to cover a lot of real scenario user behavior in our e2e functional test cases.

As the test goes on, it makes a lot of rest calls to complete the test cases. When we cover different browser in sauce lab it multiplies 5-9 times.

What I want is to mock all the rest calls so that there will not be any real calls to the actual server but internally it will be handled. its for functional e2e test not unit test as we mocked all unit tests using jasmine spyOn.

I have explored json-server and $httpBackend of protractor. son-server did not fit as it does not handles app post, put, delete calls well. in case of $httpBackend

I have gone through this post and its for andularJs app not angular app and also its all about single rest call mocking for angularJs not for all rest calls.

Also looked this angularjs multi mock for angularjs and its also for angularjs not angular and looks like this changes the original rest url for query parameter.

1

There are 1 answers

3
glucas On

Mocking network calls is not supported yet by Protractor for Angular 2+ applications. See this post and the corresponding issue on github.

Personnally, I used ng-apimock plugin to mock all network calls to the backend with a proxy.

It works really well and is simple to configure. Just follow the configuration for Angular application here