Add some way to mock and spy on default ES modules
In the process of eliminating ~"technical debt" by moving away from global variables (#20983 (closed)), we've started to come across some unexpected issues relating to testing.
Where previously, we might spy on an object by doing something like:
spyOn(window, '$');
We can no longer do this when our modules are referencing jQuery directly via import $ from 'jquery';
instead of through window.$
. We actually need to reach into the module for jQuery to "rewire" its definition. There are a few libraries that can do this, and many are outlined in this helpful stackoverflow thread.
It's worth considering which of the common solutions to this problem are best for our uses, and then add this method into our test workflow and update our test documentation.
Edited by Filipa Lacerda