Dynamical URL in $httpbackend - Angular unit testing
<p>I am trying to dynamically add URL parameter to <code>$httpbackend.whenGET</code></p>

<pre><code>urlAll = "http://localhost:8080/api/Log";
urlById = "http://localhost:8080/api/Log?id=";
</code></pre>

<ul>
<li><code>$httpBackend.whenGET(urlAll).respond(...);</code> - This is Working fine</li>
<li><code>$httpBackend.whenGET(urlById).respond(...);</code> - Not working</li>
</ul>

<p>I append id dynamically to <code>urlById</code> when I call mock service.  Since it is a dynamic value and the url is changing with dynamic id value, url is not matching with <code>urlById</code> (which is passed to <code>httpbackend</code>).  Hence, throwing below exception.</p>

<blockquote>
  <p>Unexpected request: <code>GET /http:\/\/localhost:8080\/api\/Log?id=/1e970422-a1a7-4ea5-9f74-1c84b53d7bc4</code><br>
  No more request expected</p>
</blockquote>

<p>Gone through different posts and tried with regex.  but ended up with below exception:</p>

<blockquote>
  <p>Unexpected request: <code>GET /http:\/\/localhost:8080\/api\/Log\?id=.*/14f99a26-7850-4aa6-9953-db73fb1a1cab</code><br>
  Expected GET <code>/http:\/\/localhost:8080\/api\/Log\?id=.*/.*/g</code></p>
</blockquote>

<p>Any idea on how to add dynamical url to <code>$httpbackend</code>?</p>

<p>Most of the posts say the theoretical solutions and some posts given code changes, which didn't work.  Any idea on what is wrong above?</p>