2019-10-02 05:05:53 -04:00
|
|
|
function hasHiddenStyle(node) {
|
|
|
|
if (!node.style) {
|
|
|
|
return false;
|
|
|
|
} else if (node.style.display === 'none' || node.style.visibility === 'hidden') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-26 19:09:19 -05:00
|
|
|
function createDefaultClientRect(node) {
|
|
|
|
const { outerWidth: width, outerHeight: height } = node;
|
|
|
|
|
2019-10-02 05:05:53 -04:00
|
|
|
return {
|
2020-02-26 19:09:19 -05:00
|
|
|
bottom: height,
|
|
|
|
height,
|
2019-10-02 05:05:53 -04:00
|
|
|
left: 0,
|
2020-02-26 19:09:19 -05:00
|
|
|
right: width,
|
2019-10-02 05:05:53 -04:00
|
|
|
top: 0,
|
2020-02-26 19:09:19 -05:00
|
|
|
width,
|
2019-10-02 05:05:53 -04:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is needed to get the `toBeVisible` matcher to work in `jsdom`
|
|
|
|
*
|
|
|
|
* Reference:
|
|
|
|
* - https://github.com/jsdom/jsdom/issues/1322
|
|
|
|
* - https://github.com/unindented/custom-jquery-matchers/blob/v2.1.0/packages/custom-jquery-matchers/src/matchers.js#L157
|
|
|
|
*/
|
|
|
|
window.Element.prototype.getClientRects = function getClientRects() {
|
|
|
|
let node = this;
|
|
|
|
|
|
|
|
while (node) {
|
|
|
|
if (node === document) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasHiddenStyle(node)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2020-02-26 19:09:19 -05:00
|
|
|
return [createDefaultClientRect(node)];
|
2019-10-02 05:05:53 -04:00
|
|
|
};
|