AngularJS Protractor E2E Mocking
Asked Answered
F

2

4

I have an Angular SPA retrieving its data from a node backend. Since the node project is fully covered with tests I want to mock the Angular HTTP calls. (I do not want to start a discussion about functional-/smoke-tests in general, thanks).

What I'd like to have is s.th. like this

Api = $injector.get('Api');
sinon.mock(Api, 'getSomethingFromServer').andRespondWith({foo: 'bar'})
assert(Api.getSomethingFromServer.wasCalledOnce);

But no matter how I can't find a nice solution. I found several posts regarding the same issue. For example this one.

Since protractor is changing a lot and frequently, I just like to ask here on SO if anyone found a proper solution for mocking the HTTP requests.

Frowsy answered 12/2, 2014 at 11:45 Comment(1)
Maybe this approach works for you: https://mcmap.net/q/444940/-mocking-and-stubbing-with-protractorZamarripa
N
0

we are currently doing that using http://apiary.io
Besides being able to "mock" your responses, you get a nice API description as a bonus! What we do is we run the Angular app against a proxy, which depending on whether we are in dev or in production can forward either to real backend or the one provided by apiary.

Nickelplate answered 13/2, 2014 at 8:8 Comment(1)
It looks like it's a nice piece of software, at least worth looking into it on more depth. But I would build a seperate API server rather reluctantly. It seems to be too much overhead from my point of view. But thanks for the link though.Frowsy
I
0

I agree with previous answer. An answer to frequent change of Protractor is to completly decorrelate the backend from the system under test, no matter if it is mock, stub, or fake.

The difficulty is to maintain a strong coherence with the real backend, but it is not said that it is more overhead than trying to maintain an always changing way of mocking with angular.

Isothere answered 13/2, 2014 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.