atecarlos / protractor-http-mock

A library designed to work alongside Protractor for setting up mocks for your HTTP ajax requests.
MIT License
173 stars 70 forks source link

transformResponse executes twice #59

Closed hugobast closed 8 years ago

hugobast commented 8 years ago

This is weird I really don't know what's going on and I am going to try to provide as much details as I can muster.

First, this is an Ionic project so that probably matters impact. Second this API call is handled by an ngResource model.

So I am in a protractor test and brower paused at the point before the API call so I can open up Chrome debugger and walk through it.

The first pass calls the transform through here: https://github.com/atecarlos/protractor-http-mock/blob/master/lib/httpMock.js#L75

The second pass calls the transform through here: https://github.com/atecarlos/protractor-http-mock/blob/master/lib/httpMock.js#L78

This is a lot less information than I would like, shot in the dark maybe, I'll keep investigating and see what I can turn up.

hugobast commented 8 years ago

Is the expectation that transformResponse interceptors are idempotent?

hugobast commented 8 years ago

I think I might finally understand:

This loop: https://github.com/atecarlos/protractor-http-mock/blob/master/lib/httpMock.js#L68

Say we have 2 interceptors configured and also have one transformResponse. This loop will apply the transformResponse for every interceptors. In my case that's 2 but it could easily be 3+. Am I missing something? Is this working as intended?

atecarlos commented 8 years ago

@hugobast I understand the correct behavior is that the transformResponse is called first and then passed into the interceptors. It should not be called for every interceptor. I'll look into this and your PR.

atecarlos commented 8 years ago

This has been fixed in version 0.2.0. Let me know how that works for you.