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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/angularjs/144432.html

猜你在找的Angularjs相关文章