加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – mock $httpBackend正则表达式不匹配

发布时间:2020-12-17 07:40:42 所属栏目:安全 来源:网络整理
导读:我正在尝试将一个网址与正则表达式匹配.但是正则表达式不符合. $httpBackend.whenGET('/^rest/find-reservations?.*/)').respond(function () { return [200,['succes'],{}]; }); 我继续收到以下错误: Error: Unexpected request: GET rest/find-reservat
我正在尝试将一个网址与正则表达式匹配.但是正则表达式不符合.
$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无关.

从$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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读