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

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...