cusejuice
cusejuice

Reputation: 10681

Unit test $httpBackend with query params

Using $httpBackend, how can I use expectGET with a url that has query params? The order doesn't matter, and the value doesn't matter.

$httpBackend
  .expectGET('/api/my_endpoint/example?X=false&Y=someethingelse&Z=anotherthing')
  .respond(200, {});

Using $resource this is how I declare it:

  get: {
      method: 'GET',
      url: '/api/my_endpoint/example',
      params: {
        X: '@X',
        Y: '@Y',
        Z: '@Z',
      }
    }

Upvotes: 2

Views: 1749

Answers (1)

rainerhahnekamp
rainerhahnekamp

Reputation: 1136

You can also use a regular expression instead of a string for the url parameter. So

$httpBackend
    .expectGET(/\/api\/my_endpoint\/example.*/)
    .respond(200, {});

If it gets more complex a function can also be set.

Upvotes: 1

Related Questions