https://developer.mozilla.org/en-US/docs/Web/API/Window.getSelection
Even a nonfunctioning shim would go a long way. Currently I just do the following:
window.document.getSelection = function() { return { addRange: function() {}, removeAllRanges:function() { } } };
Just to avoid "cannot call undefined" when running getSelection().
We're not really in the business of nonfunctioning shims, but you're welcome to add that to your own jsdom windows.
Any ideas on how to bake this into how Jest uses jsdom?
Not sure myself; @Sebmaster is a bit more familiar with jest, but I think the Jest issue tracker will be your best bet.
@domenic thanks, got the shim I needed by adding a version of @tolmasky's code in a Jest helper:
// spec/javascripts/helpers/jest-env.js
// window.getSelection isn't in jsdom
// https://github.com/tmpvar/jsdom/issues/937
window.getSelection = function() {
return {
addRange: function() {},
removeAllRanges:function() {}
};
};
and linking to the above file via Jest's config.setupEnvScriptFile.
Most helpful comment
@domenic thanks, got the shim I needed by adding a version of @tolmasky's code in a Jest helper:
and linking to the above file via Jest's config.setupEnvScriptFile.