mock $httpBackend regex not matched

后端 未结 4 1078
醉梦人生
醉梦人生 2021-01-04 06:59

I\'m trying to match an url with a regex. But the follwing regex doesn\'t match.

$httpBackend.whenGET(\'/^rest\\/find-reservations\\?.*/)\').respond(function         


        
4条回答
  •  隐瞒了意图╮
    2021-01-04 07:23

    If you want to match this url:

    "rest/find-reservations?end=1421424299193&reservationClass=Reservation&start=1358352299193"

    use this code:

    $httpBackend.whenGET(/^rest\/find-reservations\?.*/).respond(function () {
      return [200, ['success'], {}];
    });
    

    If you see this error Error: Unexpected request:

    It can be for some reasons:

    • You forget $httpBackend.expectGET(url).
    • The order of expectGET should be the same as the order of the requests.
    • You called $httpBackend.verifyNoOutstandingExpectation() before $httpBackend.flush().

    It is not related to $httpBackend.whenGET at all.

    From the $httpBackend docs:

    Request expectations provide a way to make assertions about requests made by the application and to define responses for those requests. The test will fail if the expected requests are not made or they are made in the wrong order

提交回复
热议问题