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-07-24 17:47:43 +01:00
parent 8a82d42bf7
commit 381e745ec8

View File

@@ -228,6 +228,7 @@ class WindowMock {
};
this._jest = jest;
this._setSpies();
this._plugJSDOM();
}
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) {
window.innerHeight = height;