http-backend-proxy icon indicating copy to clipboard operation
http-backend-proxy copied to clipboard

precedence of passThrought() calls and mock calls

Open KWodarczyk opened this issue 8 years ago • 3 comments

Hi the core anguraljs httBackend has this shortcoming that if you want some request to pass you have to specify them after your mock request, this means that you cannot have it nicely layout in the jasmine test where you would put all your passThrough() stuff in beforeAll() and the requests you actually want to mock in the test in self.

Are you able to add such a functionality ? I was hoping that the onLoad can do this but it does not.

KWodarczyk avatar Dec 07 '16 13:12 KWodarczyk

I am not sure I understand what you are trying to do. The assertion that you have to put your mocks before the passthrough makes me thing you are not setting things up quite right. If you can give me a concrete example I may be able to help you.

kbaltrinic avatar Dec 16 '16 23:12 kbaltrinic

well simply put if I do proxy.load.when('method type','/.*/',).passThrough() // for all method types e.g post,get etc. and then at the next line od actually try to mock particular url, this line will be skipped but if I do passThrough() after the line when im mocking url everything works fine

KWodarczyk avatar Dec 16 '16 23:12 KWodarczyk

Yes that makes sense. Again this has nothing to do with the proxy, this is the behavior of the httpBackend itself. When intercepting a request, it checks for registered handlers in the order they are registered. So if you register a universal passThrough first, it will be found first and used and processing stops there. If you register it last, then if a more specific one is found first, it gets used and the passthrough becomes a catch-all at the end. Think of it vaugly as a switch statement with the 'default' at the end.

kbaltrinic avatar Jan 06 '17 11:01 kbaltrinic