Make helper plug gap in JSDOM's DOM API

Errors fired from JSDOM showed it doesn't support
`window.scrollTo` (or `window.scroll` for that
matter).

This stubs it, to the extent that our use (jQuery
really) of it works.
This commit is contained in:
Tom Byers
2019-08-22 15:21:33 +01:00
parent 8a82d42bf7
commit 381e745ec8
+22
View File
@@ -228,6 +228,7 @@ class WindowMock {
}; };
this._jest = jest; this._jest = jest;
this._setSpies(); this._setSpies();
this._plugJSDOM();
} }
get top () { get top () {
@@ -260,6 +261,27 @@ class WindowMock {
} }
_plugJSDOM () {
const self = this;
// JSDOM doesn't support .scrollTo
window.scrollTo = function () {
let y;
// data sent as props in an object
if (arguments.length === 1) {
y = arguments[0].y;
} else {
y = arguments[1];
}
self.scrollTo(y);
};
}
setHeightTo (height) { setHeightTo (height) {
window.innerHeight = height; window.innerHeight = height;