Open graingert opened 8 years ago
I've got a version that just does:
import { XMLHttpRequest } from 'xmlhttprequest';
function $xhrFactoryProvider() {
this.$get = function () {
return function createXhr() {
return new XMLHttpRequest();
};
};
}
module.provider('$xhrFactory', $xhrFactoryProvider);
and it works great
this way you don't need to worry about tracking $timouts and $http requests because it's done for you and you can just use $browser.notifyWhenNoOutstandingRequests
Thanks for the suggestion, @graingert!
It was originally implemented this way because $browser.notifyWhenNoOutstandingRequests
was defined as an implementation detail of the testing framework and not something apps should be relying on. We therefore implemented something that we could rely on, assuming that nobody else would be depending on something that was described as an implementation detail. :grinning:
Now that AngularJS 1 development is kinda ramping down in favor of 2, it's probably safer to assume that $browser.notifyWhenNoOutstandingRequests
isn't going anywhere, but it still feels funny to me to depend on something that isn't even in the documentation.
Your alternative implementation does seem simpler, though presumably we'd still need to customise $httpBackend
a little to get the special-cased JSON-P emulation.
@apparentlymart ah I don't use JSON-P so I'm safe.
the other options is to use:
angular.getTestability(element).whenStable(callback)
where element is the root jsdom document.
but it just calls $browser.notifyWhenNoOutstandingRequests(callback) so I imagine it's safe.
there seems to be a lot of code in ngOverrides to count async callbacks when angular already does this in $browser.notifyWhenNoOutstandingRequests
However it turns out the overridden $httpBackend is breaking $browser.notifyWhenNoOutstandingRequests
it would be better to override $xhrFactory