我正在尝试将一个网址与正则表达式匹配.但是正则表达式不符合.
$httpBackend.whenGET('/^rest\/find-reservations\?.*/)').respond(function () { return [200,['succes'],{}]; });
我继续收到以下错误:
Error: Unexpected request: GET rest/find-reservations?end=1421424299193&reservationClass=Reservation&start=1358352299193 No more request expected
当我将正则表达式更改为绝对字符串’/ find-reservations’时,whenGET被触发.为什么是这样?
编辑:
我在嘲笑一个后端http://plnkr.co/edit/VF4KbZO3FvngWQsiUcte?p=preview
以下plnkr适用于静态网址和部分.但是在上述情况下并不是这样.
如果您要匹配此网址:
“?休息/找到的预约结束= 1421424299193&放大器; reservationClass =预订和放大器;启动= 1358352299193”
使用这段代码:
$httpBackend.whenGET(/^rest\/find-reservations\?.*/).respond(function () { return [200,['success'],{}]; });
这可能是由于某些原因:
>你忘了$httpBackend.expectGET(url).
> expectGET的顺序应与请求的顺序相同.
>在$httpBackend.flush()之前调用$httpBackend.verifyNoOutstandingExpectation().
它与$httpBackend.whenGET无关.
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