What is the difference between $httpBackend.when('')
and $httpBackend.expect('')
?
I don't know the difference between these two methods. Also the angularjs api doc does not help me.
API documentation link: https://docs.angularjs.org/api/ngMock/service/$httpBackend
$httpBackend.expect
- specifies a request expectation$httpBackend.when
- specifies a backend definitionTherefore, 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 withwhen
, the backend will respond appropriately, but it has no expectations about how many requests (if any) will come therefore will not fail the test.