Bug #35165
closedJS test improvements - assertNockRequest & nock.cleanAll()
Description
Some JS test improvements needed:
1. In global_test.setup.js we call
afterEach(() => {
nock.restore();
});
restore() restores the HTTP interceptor to the normal unmocked behaviour, which is not desired or needed after each test. Instead we should change it to
afterEach(() => {
nock.cleanAll();
});
which clears all Nock scopes, and as a side bonus allows us to remove `nock.cleanAll()` from individual test files.
2. In NockWrapper.js there's a `setInterval` which calls the jest `done()` function. The problem is that `setInterval` does not call its passed function until after `delay` milliseconds - see https://developer.mozilla.org/en-US/docs/Web/API/setInterval
So the minimum time before calling jest done() will be 500 milliseconds. This means we are wasting countless seconds on our test runs.
Jest done() should also be checked and called before the first interval.