Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngMockE2E httpBackend accept parameters for request in any order #7348

Closed
mkhanal opened this issue May 5, 2014 · 4 comments
Closed

ngMockE2E httpBackend accept parameters for request in any order #7348

mkhanal opened this issue May 5, 2014 · 4 comments

Comments

@mkhanal
Copy link

mkhanal commented May 5, 2014

when using ngMockE2E's httpBackend, the request URLs are to be matched to be equal strings. This limits mocking to have parameters in specific order (sorted alphabetically right now). Url path should be matched by string and the parameters should be parsed and compared and tested for :

  1. are all and only those parameters specified are present
  2. do the values of those parameters match expected

eg:
$httpBackend.whenGET('urlString?param2=val2&param1=val1').
respond 200, responseForVal1AndVal2

http.get("urlString", params:{param1: val1, param2: val2})

current : do not match
expected : to match

The workaround right now is to sort all query params alphabetically.This is ok for small amount of mocking, but when it is needed for a lot of data, like for protractor testing for a client side only app where all backend (or most) need to be mocked, this becomes a big pain.

@btford btford added this to the Backlog milestone Jul 22, 2014
@btford btford removed the gh: issue label Aug 20, 2014
@pkozlowski-opensource
Copy link
Member

Yeh, I can totally feel the pain :-/ We've got an issue for this already:#7348
I think we should expose somehow the service that serialises request params so people can use it from tests. I'm going to push for this in 1.4 (or even 1.3 if we can do this without any breaking changes).

Let's move the discussion to #7348

@shahata
Copy link
Contributor

shahata commented Nov 25, 2014

@pkozlowski-opensource did you mean to close this issue? It seems that this is the issue you wanted to move the discussion to. Or did you mean to refer a different issue?

@pkozlowski-opensource
Copy link
Member

@shahata oh, you are right! I've meant to close it as a duplicate of #3311

@thynctank
Copy link
Contributor

For those of us locked on 1.2, another workaround is regex when() calls, leaving the query params out or writing some potentially-complex regexes, and manually/with-library-of-choice parsing out query params from the url parameter in the corresponding respond() call.

You may run into issues where similar endpoints need to be defined in a specific order (as @mkhanal mentioned) because of this. (or again your regexes need to get more complex/specific...)

As pretty as that is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants