diff --git a/test/helpers/jsdom.js b/test/helpers/jsdom.js index 8925255..ec428e2 100644 --- a/test/helpers/jsdom.js +++ b/test/helpers/jsdom.js @@ -2,6 +2,34 @@ var jsdom = require('jsdom'); +/** + * Borrowed from: https://github.com/tmpvar/jsdom/issues/135#issuecomment-68191941 + */ +function applyJsdomWorkaround(window) { + Object.defineProperties(window.HTMLElement.prototype, { + offsetLeft: { + get: function () { + return parseFloat(window.getComputedStyle(this).marginLeft) || 0; + } + }, + offsetTop: { + get: function () { + return parseFloat(window.getComputedStyle(this).marginTop) || 0; + } + }, + offsetHeight: { + get: function () { + return parseFloat(window.getComputedStyle(this).height) || 0; + } + }, + offsetWidth: { + get: function () { + return parseFloat(window.getComputedStyle(this).width) || 0; + } + } + }); +} + function setupDom() { var baseMarkup = '', window = jsdom.jsdom(baseMarkup).defaultView; @@ -9,6 +37,7 @@ function setupDom() { global.window = window; global.document = window.document; global.navigator = window.navigator; + applyJsdomWorkaround(window); } setupDom();