gpt4 book ai didi

angularjs - $httpBackend中的expect和when有什么区别

转载 作者:行者123 更新时间:2023-12-03 01:28:27 24 4
gpt4 key购买 nike

$httpBackend.when('')$httpBackend.expect('') 有什么区别?

我不知道这两种方法有什么区别。另外,angularjs api 文档对我没有帮助。

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

最佳答案

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

From: https://docs.angularjs.org/api/ngMock/service/$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.

因此,这意味着如果您使用 expect 设置请求期望,如果您没有得到完全相同的请求,则测试将会失败,完全 次数。但是,如果您使用 when 设置它,后端将做出适当的响应,但它不会预期将有多少请求(如果有),因此不会使测试失败。

关于angularjs - $httpBackend中的expect和when有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27945758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com