是什么在$ httpBackend期望,当之间的区别 [英] What is the difference between expect and when in $httpBackend

查看:145
本文介绍了是什么在$ httpBackend期望,当之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知这两种方法之间的差异。另外,angularjs API文档不帮助我。

I don't know the difference between these two methods. Also the angularjs api doc does not help me.

推荐答案

$ httpBackend.expect - 指定要求的期望结果
$ httpBackend.when - 指定后端定义

$httpBackend.expect - specifies a request expectation
$httpBackend.when - specifies a backend definition

从:<一href=\"https://docs.angularjs.org/api/ngMock/service/\">https://docs.angularjs.org/api/ngMock/service/$httpBackend

  请求期望提供一种方法,使有关应用程序的请求断言,并定义这些请求的响应。如果预期的请求没有提出或他们是在错误的顺序进行的测试将失败。

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.

因此​​,这意味着,如果你设置一个请求期望期望如果你没有得到的确切的相同的请求会导致测试失败,确切的次数。但是,如果你把它,后端会做出适当的反应,但它不知道多少个请求(如有)将来吧不会失败测试的预期。

Therefore, it means that if you set a request expectation with expect the test will fail if you don't get the exact same request, exact number of times. However if you set it with when, the backend will respond appropriately, but it has no expectations about how many requests (if any) will come therefore will not fail the test.

这篇关于是什么在$ httpBackend期望,当之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆