微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

$ 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,则后端将会适当地进行响应,但是对于有多少个请求(如果有的话)将不会有任何预期,因此不会失败。

原文地址:https://www.jb51.cc/angularjs/144432.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐