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

angularjs – $httpBackend中期望和时间之间有什么区别?

发布时间:2020-12-17 08:11:44 所属栏目:安全 来源:网络整理
导读:$ httpBackend.when(”)和$ httpBackend.expect(”)之间有什么区别? 我不知道这两种方法的区别。另外,angularjs api doc并没有帮助我。 API文档链接:https://docs.angularjs.org/api/ngMock/service/ $ httpBackend $ httpBackend.expect – 指定请求期望
$ httpBackend.when(”)和$ httpBackend.expect(”)之间有什么区别?

我不知道这两种方法的区别。另外,angularjs api doc并没有帮助我。

API文档链接:https://docs.angularjs.org/api/ngMock/service/ $ httpBackend

$ httpBackend.expect – 指定请求期望
$ httpBackend.when – 指定后端定义

From: 07000$httpBackend
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.

Backend definitions allow you to define a fake backend for your application which doesn’t assert if a particular request was made or not,it just returns a trained response if a request is made. The test will pass whether or not the request gets made during testing.

因此,这意味着如果您设置请求期望,如果您没有获得完全相同的请求,确切次数,则测试将失败。但是,如果您将其设置为when,则后端将会适当地进行响应,但是对于有多少个请求(如果有的话)将不会有任何预期,因此不会失败。

(编辑:李大同)

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

    推荐文章
      热点阅读