Project

General

Profile

Actions

Bug #35165

closed

JS test improvements - assertNockRequest & nock.cleanAll()

Added by Jeremy Lenz over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Tests
Target version:
Difficulty:
Triaged:
Yes
Fixed in Releases:
Found in Releases:

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.

Actions

Also available in: Atom PDF