Make unmocked requests fail in Jest again
What does this MR do?
EE port: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/15400
Normally, any unmocked HTTP request via axios
or jquery
fails a test. However, since gitlab-ce/!29272 (merged), where manual mocks were introduced for ~/lib/utils/axios_utils
and jquery
, unmocked requests simply raise an error, which when caught don't fail the test and pass silently.
This MR makes unmocked requests explicitly call Jasmine's fail()
global so that tests fail unconditionally.
Why is this regression annoying?
Because our style linter enforces .catch()
blocks on any Promise. That means that any axios
request with a .then()
must also have a .catch()
, which catches the unmocked request error.
global.fail()
?
Why - It's observable and mockable using
jest.spyOn(global, 'fail')
. - There's a single instance of it across all tests.
- It can be used outside the scope of
it()
and{before,after}{Each,All}()
.
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry for user-facing changes, or community contribution. Check the link for other scenarios.
-
Documentation created/updated or follow-up review issue created -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Performance and Testing
Edited by Martin Hanzel