Skip to content

Ensure that Ajax requests are mocked in tests

I counted more than 60 Ajax requests in the JavaScript tests which are not mocked and therefore lead to a 404 error in the log. This is bad for the following reasons:

  • making a real request takes (unnecessarily) more time than a mocked one
  • the requested URL could be reachable so that the test may fail with hard to debug errors because of unexpected data
  • tests may not cover the situation well because only one type of response (404) is received
  • Karma output is full of 404 errors which may cause overlooking other errors

A simple approach would be to monkey patch XMLHttpRequest.prototype.open so that it fails the current test.

Edited by Inactive Account