Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Angularjs 教程使用 $http 服务展示了一些东西,然后使用 $httpBackend 模拟进行了测试。它没有解释的是为什么你模拟 $httpBackend 而不仅仅是模拟 $http 服务本身?任何人都可以阐明这一点吗?
你不嘲笑$httpBackend。您可以使用它来模拟$http发出的实际 HTTP 请求。我想你可能只是模拟$http自己,但$httpBacked提供了很多功能来断言某些请求已发出(expect方法)和只是在响应中进行模拟(when方法)。简而言之,$httpBacked使测试使用的代码$http变得更加容易。
$httpBackend
$http
$httpBacked
expect
when