[BUGFIX] Non reset pending ajax count

An alternative to #4548 with a test and a small cleanup.

`pendingAjaxRequests` should not be reset upon `setupForTesting`. Doing so means that an in-flight request might be disregarded, and when the `ajaxComplete` event for it fires the count of in-flights goes negative.