Mockify jquery and axios packages into `spec/frontend`
What does this MR do?
Fixes #60136 (closed)
Makes manual mocks out of the jquery
and ~/lib/utils/axios_helper
packages. These mocks will throw Errors on unmocked HTTP requests.
Why?
Unit tests shouldn't make net requests. There was code in a global before_each
that mocked Axios so that all attempts at a request result in an Error. I feel like this is a task more suited for a mock.
See !29129 (closed)
This MR is like !29129 (closed), except that this one moves Jest manual mocks away from the automatic __mocks__
folder structure and into spec/frontend/mocks
, to keep all mocks in one place. Since Jest won't find them implicitly, every mock needs to be registered using jest.mock()
, which is currently done in test_setup.js
via mocks_helper.js
.
Documentation is in !30791 (merged)
Advantages to manually declaring mocks
- It's more explicit
- Unbloats
test_setup.js
. - Manual mocks are more pluggable if we want to change mock implementations down the road.
- Manual mocks stay in place if Jest's module cache is cleared within a test (this is an edge case).
- Mock implementations live in the
spec/frontend/
directory
Drawbacks
- Dependencies of mocks are unmockable without a
resetModules()
call - Devs need to be aware of the convention of putting mocks in the proper place