0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Fixed resize observer error in tests

- resize observer used in auth frame is not available in Jest, so we mock it instead
- ignores missing methods on resize observer for tests
This commit is contained in:
Rishabh 2022-07-28 19:01:24 +05:30
parent 9afb36fa53
commit beb8807966
2 changed files with 8 additions and 2 deletions

View file

@ -22,7 +22,7 @@ export default class IFrame extends Component {
this.forceUpdate();
if (this.props.onResize) {
(new ResizeObserver(_ => this.props.onResize(this.iframeRoot))).observe(this.iframeRoot);
(new ResizeObserver(_ => this.props.onResize(this.iframeRoot)))?.observe?.(this.iframeRoot);
}
}
}

View file

@ -3,3 +3,9 @@
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn()
}));