From 381e745ec8334aaf69f5fad48e3ad50a5fc24158 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Wed, 24 Jul 2019 17:47:43 +0100 Subject: [PATCH] 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. --- tests/javascripts/support/helpers.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/javascripts/support/helpers.js b/tests/javascripts/support/helpers.js index 5d3df2c22..9e859e44a 100644 --- a/tests/javascripts/support/helpers.js +++ b/tests/javascripts/support/helpers.js @@ -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;