Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions cypress/support/ResizeObserverMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
class ResizeObserverMock {
constructor(callback) {
this.callback = callback;
this.elements = new Set();
this.handleResize = this.handleResize.bind(this);
this._window = null;
this._listening = false;
}

observe(element) {
if (!this._window && element && element.ownerDocument) {
this._window = element.ownerDocument.defaultView || null;
}

const win =
this._window || (typeof window !== 'undefined' ? window : null);

if (!this.elements) return;
this.elements.add(element);

if (!this._listening && win) {
win.addEventListener('resize', this.handleResize);
this._listening = true;
}

this.trigger();
}

unobserve(element) {
this.elements.delete(element);
const win =
this._window || (typeof window !== 'undefined' ? window : null);
if (this.elements.size === 0 && this._listening && win) {
win.removeEventListener('resize', this.handleResize);
this._listening = false;
}
}

disconnect() {
this.elements.clear();
const win =
this._window || (typeof window !== 'undefined' ? window : null);
if (this._listening && win) {
win.removeEventListener('resize', this.handleResize);
this._listening = false;
}
}
Comment on lines +10 to +47

handleResize() {
this.trigger();
}

trigger() {
if (this.elements.size === 0) return;

const entries = Array.from(this.elements).map(e => ({
target: e,
contentRect: e.getBoundingClientRect(),
}));

const win =
this._window || (typeof window !== 'undefined' ? window : null);
const raf =
win && typeof win.requestAnimationFrame === 'function'
? win.requestAnimationFrame.bind(win)
: typeof requestAnimationFrame === 'function'
? requestAnimationFrame
: cb => setTimeout(cb, 0);

raf(() => {
this.callback(entries, this);
Comment on lines +10 to +71
});
}
}

export default ResizeObserverMock;
13 changes: 5 additions & 8 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
* See https://github.com/cypress-io/cypress/issues/20341
* See https://github.com/cypress-io/cypress/issues/29277
*/
Cypress.on('uncaught:exception', err => {
if (
err.message.includes(
'ResizeObserver loop completed with undelivered notifications'
)
) {
return false;
}

import ResizeObserverMock from './ResizeObserverMock';

Cypress.on('window:before:load', win => {
win.ResizeObserver = ResizeObserverMock;
});
15 changes: 12 additions & 3 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "e2e"
"rootDir": ".",
"noEmit": true,
"allowJs": true,
"types": [
"cypress",
"node"
]
},
"types": ["cypress", "node"]
}
"include": [
"**/*.ts",
"**/*.js"
]
}
Loading